View Full Version : preg replace problem

05-21-2008, 03:15 AM

I have this line in a mysql function in my PHP app.

$query = preg_replace('#\{(.*)\}#e', 'tab("\1")', $query);

It is supposed to take everything between { and } and replace with with a table name supplied from the tab() function. Now it works file when I have just one table name, but when I have two table names it functions incorrectly, replacing everything between the first { and the last }.

For example,

FROM {table1} t, {table2} j

would read everything from the t in table1 to the 2 in table2.

Is there a way to fix this?


05-21-2008, 06:38 AM
Use the U (ungreedy) modifier:

$query = preg_replace('#\{(.*)\}#Ue', 'tab("\1")', $query);

05-21-2008, 07:53 PM
Perfect, thanks!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum