note 21735 added to function.str-replace
| From: | tapken at engter dot de | Date: | Fri, 24 May 2002 19:34:55 +0000 |
| Subject: | note 21735 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31006@lists.php.net to get a copy of this message | ||
If you want to replace only the first occurence of a string you can use this function:
function str_replace_once($needle, $replace, $haystack) {
// Looks for the first occurence of $needle in $haystack
// and replaces it with $replace.
$pos = strpos($haystack, $needle);
if ($pos === false) {
// Nothing found
return $haystack;
}
return substr_replace($haystack, $replace, $pos, strlen($needle));
}
--
http://www.php.net/manual/en/function.str-replace.php
http://master.php.net/manage/user-notes.php?action=edit+21735
http://master.php.net/manage/user-notes.php?action=delete+21735
http://master.php.net/manage/user-notes.php?action=reject+21735