note 64778 added to function.preg-replace

From: Date: Thu, 20 Apr 2006 15:37:37 +0000
Subject: note 64778 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-108819@lists.php.net to get a copy of this message
I just wanted to give an example for some people that have the problem, that their match is taking away too much of the string. I wanted to have a function that extracts only wanted parameters out of a http query string, and they had to be flexible, eg 'updateItem=1' should be replaced, as well as 'updateCategory=1', but i sometimes ended up having too much replaced from the query. example: my query string: 'updateItem=1&itemID=14' ended up in a query string like this: '4' , which was not really covering the plan ;) i was using this regexp: preg_replace('/&?update.*=1&?/','',$query_string); i discovered, that preg_replace matches the longest possible string, which means that it replaces everything from the first u up to the 1 after itemID= I assumed, that it would take the shortest possible match. ---- Server IP: 217.13.201.10 Probable Submitter: 84.58.212.195 ---- 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.preg-replace.php Edit -- http://master.php.net/note/edit/64778 Del: integrated -- http://master.php.net/note/delete/64778/integrated Del: useless -- http://master.php.net/note/delete/64778/useless Del: bad code -- http://master.php.net/note/delete/64778/bad+code Del: spam -- http://master.php.net/note/delete/64778/spam Del: non-english -- http://master.php.net/note/delete/64778/non-english Del: in docs -- http://master.php.net/note/delete/64778/in+docs Del: other reasons-- http://master.php.net/note/delete/64778 Reject -- http://master.php.net/note/reject/64778 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#108819) next »