note 105939 added to function.str-replace

From: Date: Tue, 27 Sep 2011 06:20:01 +0000
Subject: note 105939 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-183464@lists.php.net to get a copy of this message
Note that this does not replace strings that become part of replacement strings. This may be a problem when you want to remove multiple instances of the same repetative pattern, several times in a row. If you want to remove all dashes but one from the string '-aaa----b-c-----d--e---f' resulting in '-aaa-b-c-d-e-f', you cannot use str_replace. Instead, use preg_replace: $challenge = '-aaa----b-c-----d--e---f'; echo str_replace('--', '-', $challenge).'<br>'; echo preg_replace('/--+/', '-', $challenge).'<br>'; This outputs the following: -aaa--b-c---d-e--f -aaa-b-c-d-e-f ---- Server IP: 69.147.83.197 Probable Submitter: 212.159.240.18 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/105939 Del: integrated -- https://master.php.net/note/delete/105939/integrated Del: useless -- https://master.php.net/note/delete/105939/useless Del: bad code -- https://master.php.net/note/delete/105939/bad+code Del: spam -- https://master.php.net/note/delete/105939/spam Del: non-english -- https://master.php.net/note/delete/105939/non-english Del: in docs -- https://master.php.net/note/delete/105939/in+docs Del: other reasons-- https://master.php.net/note/delete/105939 Reject -- https://master.php.net/note/reject/105939 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#183464) next »