note 74071 added to function.str-replace
| From: | patrick at rocksolidsystems dot biz | Date: | Thu, 22 Mar 2007 21:30:05 +0000 |
| Subject: | note 74071 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124732@lists.php.net to get a copy of this message | ||
With reference to the google type searches above ...
This is a case insensitive replace....
This code below will highlight the "found" text in red and return the string unaltered (in
terms of case).
<?php
function turn_red($haystack,$needle)
{
$h=strtoupper($haystack);
$n=strtoupper($needle);
$pos=strpos($h,$n);
if ($pos !== false)
{
$var=substr($haystack,0,$pos)."<font
color='red'>".substr($haystack,$pos,strlen($needle))."</font>";
$var.=substr($haystack,($pos+strlen($needle)));
$haystack=$var;
}
return $haystack;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 196.25.255.214 (proxied: 41.241.22.95, 198.54.202.18)
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/74071
Del: integrated -- https://master.php.net/note/delete/74071/integrated
Del: useless -- https://master.php.net/note/delete/74071/useless
Del: bad code -- https://master.php.net/note/delete/74071/bad+code
Del: spam -- https://master.php.net/note/delete/74071/spam
Del: non-english -- https://master.php.net/note/delete/74071/non-english
Del: in docs -- https://master.php.net/note/delete/74071/in+docs
Del: other reasons-- https://master.php.net/note/delete/74071
Reject -- https://master.php.net/note/reject/74071
Search -- https://master.php.net/manage/user-notes.php