note 78915 deleted from function.str-replace by felipe
| From: | felipe@php.net | Date: | Sun, 23 Mar 2008 23:06:38 +0000 |
| Subject: | note 78915 deleted from function.str-replace by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137428@lists.php.net to get a copy of this message | ||
Note Submitter: jmack at parhelic dot com
----
The ReplaceOne function above does not work properly in all cases. (Not even using the provided
example.)
Here is my replacement:
function str_replace_once($search, $replace, $subject)
{
if(($pos = strpos($subject, $search)) !== false)
{
$ret = substr($subject, 0, $pos).$replace.substr($subject, $pos + strlen($search));
}
else
{
$ret = $subject;
}
return($ret);
}