This is in wordpress (not sure that makes a difference)
This bit of php outputs the post title
<?php echo $data['nameofpost']; ?>
It’s simple text which can be anywhere up to 100 chars long. What i’d like is if the chars outputted are over 20 long to display ‘…’ or simply nothing at all.
Thanks
After you check the string length with strlen use substr
Outputs
Another way to cut the string off at the end of a word is with a regex. This one is set to cut off at 100 characters or the nearest word break after 100 characters:
A common improvement would be to try to cut the string at the end of a word:
If you are using UTF-8 strings you would want to use the
mb_
multibyte versions of the string ops to count characters more appropriately.in your theme file use something like this
try using
<div class="teaser-text"><?php the_content_limit(100, ''); ?></div>
then in the functions.php files, use this
good luck 🙂
For
$data['nameofpost']
greater then 20 chars it will output the first 17 plus three dots...
.