note 67979 added to function.str-replace

From: Date: Sat, 08 Jul 2006 07:53:34 +0000
Subject: note 67979 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-114590@lists.php.net to get a copy of this message
About xinobit's function -> what if $search, $replace or/and $subject are arrays?.. ;) I supplemented the code to support that possibility but the result was a bit heavy... and slow! preg_replace() is about 5 times faster! :) (more or less depending on the length of $subject) So, a little example of function: <?php function str_replace_limit($search, $replace, $subject, $limit=-1) { // constructing mask(s)... if (is_array($search)) { foreach ($search as $k=>$v) { $search[$k] = '' . preg_quote($search[$k],'') . '`'; } } else { $search = '' . preg_quote($search,'') . '`'; } // replacement return preg_replace($search, $replace, $subject, $limit); } ?> (of course you could insert a "&$count" argument for PHP >= 5.1.0) ---- Server IP: 66.163.161.117 Probable Submitter: 89.83.245.65 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/note/edit/67979 Del: integrated -- http://master.php.net/note/delete/67979/integrated Del: useless -- http://master.php.net/note/delete/67979/useless Del: bad code -- http://master.php.net/note/delete/67979/bad+code Del: spam -- http://master.php.net/note/delete/67979/spam Del: non-english -- http://master.php.net/note/delete/67979/non-english Del: in docs -- http://master.php.net/note/delete/67979/in+docs Del: other reasons-- http://master.php.net/note/delete/67979 Reject -- http://master.php.net/note/reject/67979 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114590) next »