note 54978 added to function.str-ireplace

From: Date: Thu, 21 Jul 2005 12:02:16 +0000
Subject: note 54978 added to function.str-ireplace
Groups: php.notes 
Request: Send a blank email to php-notes+get-92251@lists.php.net to get a copy of this message
Lumpio- and Andrew got the fourth parameter of preg_replace wrong, which should not be count but limit. Plus, $count needs to be a reference to make sense. So it comes down to this: <?php function str_ireplace($search, $replace, $subject, &$count) { if (is_array($search)) { foreach ($search as $word) { $words[] = '/'.preg_quote($word, '/').'/i'; } } else { $words = '/'.preg_quote($search, '/').'/i'; } return preg_replace($words, $replace, $subject, -1, $count); } ?> It would also be possible to add a $limit parameter with the default value -1. Notice that it's not possible to make &$count optional. So if you don't want to use it, you'll have to remove it. ---- Manual Page -- http://www.php.net/manual/en/function.str-ireplace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54978 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54978&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54978&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54978&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54978&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54978&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54978&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54978&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92251) next »