note 85288 added to function.preg-replace

From: Date: Sat, 23 Aug 2008 20:42:13 +0000
Subject: note 85288 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-143776@lists.php.net to get a copy of this message
correction. preg_replace is greedy by default, and the behaviour of ? on the pattern is to make it non-greedy contrary to what i read on PCRE docs. $str ="asdfd adsfd aaaadasd"; $str = preg_replace("/(a)(.*)(d)/","a($2)d",$str); a(sdfd adsfd aaaadas)d $str = preg_replace("/(a)(.*)?(d)/U","a($2)d",$str); a(s)dfd a()dsfd a(aaa)da(s)d which is what i wanted. ---- Server IP: 59.162.86.33 Probable Submitter: 122.167.32.146 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/85288 Del: integrated -- https://master.php.net/note/delete/85288/integrated Del: useless -- https://master.php.net/note/delete/85288/useless Del: bad code -- https://master.php.net/note/delete/85288/bad+code Del: spam -- https://master.php.net/note/delete/85288/spam Del: non-english -- https://master.php.net/note/delete/85288/non-english Del: in docs -- https://master.php.net/note/delete/85288/in+docs Del: other reasons-- https://master.php.net/note/delete/85288 Reject -- https://master.php.net/note/reject/85288 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143776) next »