Forum Moderators: coopster

Message Too Old, No Replies

Pcre

         

OrlandoM

11:56 am on Jan 14, 2010 (gmt 0)

10+ Year Member



Hi everyone. I'm new one to PCRE and I need to modify current uri of page and modify low_price and hi_price inside it.
For example, $url = $_SERVER["REQUEST_URI"] returns such string "http://somesite.com/search.php?s=intel&low_price=50&hi_price=100&page=2".
I'm writing such wrong code

preg_replace("/low_price=/\d+/&hi_price=/\d+", "low_price=200&hi_price=300", $url);

Please make corrections to my code. Thanks beforehands.

And one more question: where I can read about quantificators and grouping in PCRE? My book about PHP is to weak in this question

jamie

12:39 pm on Jan 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



at a quick glance you have too many forward slashes which aren't escaped. any pattern needs a delimiter at the begining and the end. try using # instead of /. i also find brackets help visually break up the complicated bits.

preg_replace("#low_price=([\d]+)&hi_price=([\d]+)#", "low_price=200&hi_price=300", $url);