PHP 8.5.0 Beta 1 available for testing

Voting

: max(seven, seven)?
(Example: nine)

The Note You're Voting On

marc at ermshaus dot org
16 years ago
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;
}
?>

<< Back to user notes page

To Top