469,624 Members | 910 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,624 developers. It's quick & easy.

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

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
1 2110
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.

Similar topics

3 posts views Thread by Online | last post: by
reply views Thread by Chris McKenzie | last post: by
9 posts views Thread by Whitless | last post: by
5 posts views Thread by nel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.