note 62604 deleted from function.str-replace by nlopess

From: Date: Mon, 06 Mar 2006 19:00:21 +0000
Subject: note 62604 deleted from function.str-replace by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-104925@lists.php.net to get a copy of this message
Note Submitter: fredrik AT demomusic DOT nu ---- An enhancement of str_replace_once() from below (allows use of count-parameter): function str_replace_once($needle, $replace, $haystack, &$count = null) { // 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; } //Populate $count str_replace($needle, $replace, $haystack, $count); //$count can never be more than 1 through this function if ($count >= 1) $count = 1; else $count = 0; return substr_replace($haystack, $replace, $pos, strlen($needle)); }

« previous php.notes (#104925) next »