note 10193 added to wordwrap
| From: | john at defected dot net | Date: | Tue, 19 Dec 2000 04:52:00 +0000 |
| Subject: | note 10193 added to wordwrap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-8875@lists.php.net to get a copy of this message | ||
An update to the previous note.
-------------------------------
This will return exactly how many words you tell it to, and append with whatever you specify.
function cut_string($string_to_cut, $number_words, $append="..")
{
$string = explode(" ", $string_to_cut);
for($x=0; $x < $number_words; $x++)
{
$string_return .= $string[$x] . " ";
}
$string = substr($string_return, 0, -1);
$return_string = $string.$append;
return($return_string);
}
Usage:
print(cut_string("This is a test",2));
Output:
This is..
http://www.php.net/manual/function.wordwrap.php