So if you build a news content type, you probably think you need two field to store intro and fulltext.

Well, with this script you don't have to build two field, just use introtext, and we can create the introtext automatically.

if (strlen($intro) > 200) {

// truncate string
$stringCut = substr($intro, 0, 200);

// make sure it ends in a word so "assassinate" doesn't become "ass..."
$intro = substr($stringCut, 0, strrpos($stringCut, ' ')).'[..]';
echo $intro;

Some Notes for you:

  • strip_tags is use to strip-out (erase) all the html tag, so you'll get pure text
  • you need to cut/split the intro text on the white-space, not in the word