note 64444 deleted from function.strtok by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 14:58:11 +0000 |
| Subject: | note 64444 deleted from function.strtok by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197251@lists.php.net to get a copy of this message | ||
Note Submitter: Geert
----
Shauns function needs a little update because it produces an error message that the variables $text
and $words were not defined. Written like this it won't produce an error:
<?php
function summarize($paragraph, $limit){
$tok = strtok($paragraph, " ");
$text="";
$words='0';
while($tok){
$text .= " ".$tok;
$words++;
if(($words >= $limit) && ((substr($tok, -1) == "!")||(substr($tok, -1) ==
".")))
break;
$tok = strtok(" ");
}
return ltrim($text);
}
?>