/ Published in: PHP
URL: http://www.nutt.net/2004/12/29/php-a-function-to-return-the-first-n-words-from-a-string/
Expand |
Embed | Plain Text
function shorten_string($string, $wordsreturned) /* Returns the first $wordsreturned out of $string. If string contains more words than $wordsreturned, the entire string is returned.*/ { $retval = $string; // Just in case of a problem /* Already short enough, return the whole thing*/ { $retval = $string; } /* Need to chop of some words*/ else { } return $retval; }
Comments
Subscribe to comments
You need to login to post a comment.

nice, the only snippet that works as it should! thanx!
note: you should consider changing the title to "A PHP FUNCTION TO SELECT THE FIRST WORDS FROM A STRING"