note 74503 added to function.strpos

From: Date: Sat, 14 Apr 2007 14:18:13 +0000
Subject: note 74503 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-125397@lists.php.net to get a copy of this message
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)." "; ################################ ---- Server IP: 64.71.164.2 Probable Submitter: 86.15.137.122 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/74503 Del: integrated -- https://master.php.net/note/delete/74503/integrated Del: useless -- https://master.php.net/note/delete/74503/useless Del: bad code -- https://master.php.net/note/delete/74503/bad+code Del: spam -- https://master.php.net/note/delete/74503/spam Del: non-english -- https://master.php.net/note/delete/74503/non-english Del: in docs -- https://master.php.net/note/delete/74503/in+docs Del: other reasons-- https://master.php.net/note/delete/74503 Reject -- https://master.php.net/note/reject/74503 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125397) next »