note 74503 deleted from function.strpos by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:32:21 +0000 |
| Subject: | note 74503 deleted from function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154843@lists.php.net to get a copy of this message | ||
Note Submitter:
----
Thanks to spinicrus (see above) I have sorted out a problem that was bugging me for ages. I have a
routine in Etomite Content Management System that will display a set number of characters of a news
item and invite visitors to "Read more".
Unfortunately the 400 character summary sometimes displayed a partial word at the end.
Using the following code based on spinicrus's exampleI have now overcome this.
#################################
#only full word at the end
$string=$rest;
$charToFind=" ";
$searchPos = $lentoshow;
$searchChar = '';
//
while ($searchChar != $charToFind) {
$newPos = $searchPos-1;
$searchChar = substr($string,$newPos,strlen($charToFind));
$searchPos = $newPos;
}
$rest=substr($string,0,$searchPos)." ";
################################