note 78915 added to function.str-replace

From: Date: Fri, 02 Nov 2007 00:16:39 +0000
Subject: note 78915 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-131928@lists.php.net to get a copy of this message
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); } ---- Server IP: 208.69.120.35 Probable Submitter: 209.77.137.4 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/78915 Del: integrated -- https://master.php.net/note/delete/78915/integrated Del: useless -- https://master.php.net/note/delete/78915/useless Del: bad code -- https://master.php.net/note/delete/78915/bad+code Del: spam -- https://master.php.net/note/delete/78915/spam Del: non-english -- https://master.php.net/note/delete/78915/non-english Del: in docs -- https://master.php.net/note/delete/78915/in+docs Del: other reasons-- https://master.php.net/note/delete/78915 Reject -- https://master.php.net/note/reject/78915 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131928) next »