Reputation: 2300
$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 (.*?).
Upvotes: 0
Views: 318
Reputation: 321688
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);
Upvotes: 2