By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,606 Members | 3,802 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,606 IT Pros & Developers. It's quick & easy.

REGEX: can't seem to replace LIMIT clause in query using preg_replace ($pattern, $replacement, $query)

P: n/a
Want to replace the limit clause in a query, but can't get it right.
What's wrong with this:

$pattern = "(.*)limit (.*)";
$replacement = '$1';
$replacement .= "LIMIT $limit";
$replacement .= '$2';
$query = preg_replace ($pattern, $replacement, $query);
All I get back is:

LIMIT 700

Apr 13 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
OK, my bad, the pattern needed to be case insenstive. This worked:

$pattern = "(.*)limit (.*)";
$replacement = '$1';
$replacement .= "LIMIT $limit,";
$replacement .= '$2';
$query = preg_replace ('/(.*)limit (.*)/i', $replacement, $query);
lawrence k wrote:
Want to replace the limit clause in a query, but can't get it right.
What's wrong with this:

$pattern = "(.*)limit (.*)";
$replacement = '$1';
$replacement .= "LIMIT $limit";
$replacement .= '$2';
$query = preg_replace ($pattern, $replacement, $query);
All I get back is:

LIMIT 700


Apr 13 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.