views:

89

answers:

1

i want to find first select ... from and replace that only, following code replace all select..from in sql query, i just need for first select..from

preg_replace('#select(.*?)from#is', "select count($expr) as counted from", $sql);
+1  A: 

There is a fourth optional parameter called 'limit' for preg_replace() which defines the number of replacements, and which defaults to -1 (meaning no limit)

preg_replace('#select(.*?)from#is', "select count($expr) as counted from", $sql, 1);
pavium
that was too dumb of me. thanks for the help tho.
Basit