note 85009 added to function.str-ireplace
| From: | a dot lyskawa at pp-layouts dot com | Date: | Sun, 10 Aug 2008 09:41:42 +0000 |
| Subject: | note 85009 added to function.str-ireplace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143345@lists.php.net to get a copy of this message | ||
I'm really sorry, there is a big bug in my previous mb_str_ireplace function: here's the
correct one:
<?php
/**
* Case insensitive multi-byte safe str_ireplace
* @param string $search
* @param string $replace
* @param string $subject
* @param int $count
* @param string $encoding
* @return string
*/
function mb_str_ireplace($search, $replace, $subject, $count = null, $encoding = u8) {
$l1 = mb_strlen($search, $encoding);
$l2 = mb_strlen($replace, $encoding);
$rc = 0;
$offset = 0;
while(ok($p = mb_stripos($subject, $search, $offset, $encoding)) && (is_null($count) ||
$rc <= $count)) {
if (ok($p))
$subject = mb_substr($subject, 0, $p, $encoding) . $replace . mb_substr($subject, $p + $l1,
mb_strlen($subject, $encoding), $encoding);
$offset = $p + $l2;
$rc++;
}
return $subject;
}
?>
To make it mb_str_replace - change stripos to strpos. I'm sorry for previous bug, well, this
one is tested.
I wonder should I publish my growing mb_ functions library like WORKING mb_wordwrap WITHOUT regexes
(faster)... E-mail me.
----
Server IP: 82.160.94.10
Probable Submitter: 89.76.123.253
----
Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php
Edit -- https://master.php.net/note/edit/85009
Del: integrated -- https://master.php.net/note/delete/85009/integrated
Del: useless -- https://master.php.net/note/delete/85009/useless
Del: bad code -- https://master.php.net/note/delete/85009/bad+code
Del: spam -- https://master.php.net/note/delete/85009/spam
Del: non-english -- https://master.php.net/note/delete/85009/non-english
Del: in docs -- https://master.php.net/note/delete/85009/in+docs
Del: other reasons-- https://master.php.net/note/delete/85009
Reject -- https://master.php.net/note/reject/85009
Search -- https://master.php.net/manage/user-notes.php