/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; }
URL: http://www.nutt.net/2004/12/29/php-a-function-to-return-the-first-n-words-from-a-string/