Limit Length of Text in PHP

Ok say you have a title like this:
“This is a long title for a story this is a title wow.”
And you want to have a excerpt from it.
Such as “This is a long title” instead of the whole thing

We would use the PHP substr function, which goes like this.
<?
$test = "your text here adding length here";
echo "".substr($test, 0, 25)."";
?>
$test is the text to clip, the 0 is where is starts in the phrase (0 makes it the beginning), while 25 is the amount of letter to clip.

This would make it say “your text here adding len”.

Then you could add to the end off the echo a …
like this:
echo "".substr($test, 0, 25)."...";

Related Posts Plugin for WordPress, Blogger...

Written by Andy Feliciotti

Andy Feliciotti is a UI Designer in College Park, Maryland. He diggs web design and social media, if it's on the internet he has probably seen it. You can stay up to date with what Andy does on twitter.


  • Andy Feliciotti

    Any questions, just let me know