note 93659 added to function.str-ireplace

From: Date: Tue, 22 Sep 2009 00:44:50 +0000
Subject: note 93659 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-160907@lists.php.net to get a copy of this message
@ 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? ---- Server IP: 208.69.120.35 Probable Submitter: 71.74.239.153 ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- https://master.php.net/note/edit/93659 Del: integrated -- https://master.php.net/note/delete/93659/integrated Del: useless -- https://master.php.net/note/delete/93659/useless Del: bad code -- https://master.php.net/note/delete/93659/bad+code Del: spam -- https://master.php.net/note/delete/93659/spam Del: non-english -- https://master.php.net/note/delete/93659/non-english Del: in docs -- https://master.php.net/note/delete/93659/in+docs Del: other reasons-- https://master.php.net/note/delete/93659 Reject -- https://master.php.net/note/reject/93659 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160907) next »