note 81086 added to function.substr-replace
| From: | ntoniazzi at sqli dot com | Date: | Wed, 13 Feb 2008 17:58:47 +0000 |
| Subject: | note 81086 added to function.substr-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136122@lists.php.net to get a copy of this message | ||
There is a mistake in the mb_substr_replace function below, when the $length parameter is given
negative. Here is a working version.
<?php
//Check to see if it exists in case PHP has this function later
if (!function_exists("mb_substr_replace")){
//Same parameters as substr_replace with the extra encoding parameter.
function mb_substr_replace($string, $replacement, $start, $length=null, $encoding=null) {
if ($encoding == null) $encoding = mb_internal_encoding();
if ($length == null) {
return mb_substr($string, 0, $start, $encoding) . $replacement;
}
else {
if($length < 0) $length = mb_strlen($string, $encoding) - $start + $length;
return
mb_substr($string, 0, $start, $encoding) .
$replacement .
mb_substr($string, $start + $length, mb_strlen($string, $encoding), $encoding);
}
}
}
?>
----
Server IP: 87.124.64.96
Probable Submitter: 84.14.214.74
----
Manual Page -- http://www.php.net/manual/en/function.substr-replace.php
Edit -- https://master.php.net/note/edit/81086
Del: integrated -- https://master.php.net/note/delete/81086/integrated
Del: useless -- https://master.php.net/note/delete/81086/useless
Del: bad code -- https://master.php.net/note/delete/81086/bad+code
Del: spam -- https://master.php.net/note/delete/81086/spam
Del: non-english -- https://master.php.net/note/delete/81086/non-english
Del: in docs -- https://master.php.net/note/delete/81086/in+docs
Del: other reasons-- https://master.php.net/note/delete/81086
Reject -- https://master.php.net/note/reject/81086
Search -- https://master.php.net/manage/user-notes.php