tags:

views:

54

answers:

1
$count_sql = preg_replace("/SELECT(.+?)FROM/", "SELECT COUNT(*) FROM", $sql);

It's probably pretty obvious what I'm trying to do, but I am terrible with regex.

I need to replace anything between SELECT and FROM with COUNT(*).

Tried using (.+), (.+?), (.*), and (.*?).

+2  A: 

It looks OK... does your SQL contain newlines? If so, you'll need the s modifier:

$count_sql = preg_replace("/SELECT(.+?)FROM/s", "SELECT COUNT(*) FROM", $sql);
Greg
That was it, thanks.
Samutz