note 86120 added to ref.mbstring

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
A small correction to patrick at hexane dot org's mb_str_replace function. The original function does not work as intended in case $replacement contains $needle.

<?php
function mb_str_replace($needle, $replacement, $haystack)
{
	$needle_len = mb_strlen($needle);
	$replacement_len = mb_strlen($replacement);
	$pos = mb_strpos($haystack, $needle);
	while ($pos !== false)
	{
		$haystack = mb_substr($haystack, 0, $pos) . $replacement
				. mb_substr($haystack, $pos + $needle_len);
		$pos = mb_strpos($haystack, $needle, $pos + $replacement_len);
	}
	return $haystack;
}
?>
----
Server IP: 217.13.201.10
Probable Submitter: 92.252.38.45
----
Manual Page -- http://www.php.net/manual/en/ref.mbstring.php
Edit        -- https://master.php.net/note/edit/86120
Del: integrated  -- https://master.php.net/note/delete/86120/integrated
Del: useless     -- https://master.php.net/note/delete/86120/useless
Del: bad code    -- https://master.php.net/note/delete/86120/bad+code
Del: spam        -- https://master.php.net/note/delete/86120/spam
Del: non-english -- https://master.php.net/note/delete/86120/non-english
Del: in docs     -- https://master.php.net/note/delete/86120/in+docs
Del: other reasons-- https://master.php.net/note/delete/86120
Reject      -- https://master.php.net/note/reject/86120
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.