note 68554 added to function.strpos

From: Date: Tue, 01 Aug 2006 18:54:56 +0000
Subject: note 68554 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-115424@lists.php.net to get a copy of this message
To add Anchors to all occurances of a certain word, insensive to case, but can be changed ;) function addAnchor($findme, $str, $ancFirst, $ancEnd="") { if ($ancEnd == "") {$ancEnd = substr($ancFirst,0,1).'/'.substr($ancFirst,1);} $strOut=''; $start=0; $pos = stripos($str,$findme); do { $strOut = $strOut.substr($str,$start,$pos-$start). $ancFirst.substr($str,$pos,strlen($findme)).$ancEnd; $start = $pos+strlen($findme); $pos = stripos($str,$findme,$start) ; } while ($pos !== false); return $strOut.substr($str,$start); } Here is an exemple of the call : echo addAnchor('try','Hello entry the code. Try again. Enough tRYing ?','<b>'); ---- Server IP: 195.221.21.36 Probable Submitter: 82.239.224.112 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/68554 Del: integrated -- https://master.php.net/note/delete/68554/integrated Del: useless -- https://master.php.net/note/delete/68554/useless Del: bad code -- https://master.php.net/note/delete/68554/bad+code Del: spam -- https://master.php.net/note/delete/68554/spam Del: non-english -- https://master.php.net/note/delete/68554/non-english Del: in docs -- https://master.php.net/note/delete/68554/in+docs Del: other reasons-- https://master.php.net/note/delete/68554 Reject -- https://master.php.net/note/reject/68554 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115424) next »