note 93659 deleted from function.str-ireplace by danbrown
| From: | danbrown@php.net | Date: | Tue, 22 Sep 2009 14:42:45 +0000 |
| Subject: | note 93659 deleted from function.str-ireplace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160934@lists.php.net to get a copy of this message | ||
Note Submitter: junk1 at xiaix dot com
----
@ info at daniel-marschall dot de
Sorry, but your below function does not work. It still returns whatever case is typed. Here is how
I'm using it:
<?php
function ext_str_ireplace($subject, $findme)
{
$rest = $subject;
$result = '';
$replacewith = "<span class=\"highlight_word\">" .$findme.
"</span>";
while (stripos($rest, $findme) !== false) {
$pos = stripos($rest, $findme);
// Remove the wanted string from $rest and append it to $result
$result .= substr($rest, 0, $pos);
$rest = substr($rest, $pos, strlen($rest)-$pos);
// Remove the wanted string from $rest and place it correctly into $result
$result .= str_replace('$1', substr($rest, 0, strlen($findme)), $replacewith);
$rest = substr($rest, strlen($findme), strlen($rest)-strlen($findme));
}
// After the last match, append the rest
$result .= $rest;
return $result;
}
$string1 = ext_str_ireplace($dbRowResult['partName'], $words);
echo $string1;
?>
If $dbRowResult['partName'] = RADIATOR, and someone types "rad" in the search
box,
the result comes back as "radIATOR" using the above function. This is not what I need.
Am I missing something?