note 64778 deleted from function.preg-replace by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 20:01:42 +0000 |
| Subject: | note 64778 deleted from function.preg-replace by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127696@lists.php.net to get a copy of this message | ||
Note Submitter: heppa(at)web(dot)de
----
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.