note 86177 added to function.str-replace

From: Date: Mon, 06 Oct 2008 23:12:18 +0000
Subject: note 86177 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-145109@lists.php.net to get a copy of this message
I tried max at efoxdesigns dot com solution for str_replace_once but it didn't work quite right so I came up with this solution (all params must be strings): <?php function str_replace_once($search, $replace, $subject) { $firstChar = strpos($subject, $search); if($firstChar !== false) { $beforeStr = substr($subject,0,$firstChar); $afterStr = substr($subject, $firstChar + strlen($search)); return $beforeStr.$replace.$afterStr; } else { return $subject; } } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 75.100.120.26 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/86177 Del: integrated -- https://master.php.net/note/delete/86177/integrated Del: useless -- https://master.php.net/note/delete/86177/useless Del: bad code -- https://master.php.net/note/delete/86177/bad+code Del: spam -- https://master.php.net/note/delete/86177/spam Del: non-english -- https://master.php.net/note/delete/86177/non-english Del: in docs -- https://master.php.net/note/delete/86177/in+docs Del: other reasons-- https://master.php.net/note/delete/86177 Reject -- https://master.php.net/note/reject/86177 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145109) next »