note 68554 deleted from function.strpos by bjori
| From: | bjori@php.net | Date: | Wed, 02 Aug 2006 13:08:18 +0000 |
| Subject: | note 68554 deleted from function.strpos by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-115474@lists.php.net to get a copy of this message | ||
Note Submitter: vibby at laposte dot net
Reason: useless
----
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>');