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);
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);
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);