preg_match difficulty
Posted: Tue Sep 02, 2003 2:18 pm
THanks for any advice.
I'm trying to use preg_match to match a particular SQL statement. The sql statement has to be in the following format:
1: The words SELECT followed by some text
2: The words FROM followed by some text following
3: (OPTIONAL) WHERE with some text following
4: (OPTIONAL) LIMIT with some text following
5: (OPTIONAL) ORDER with some text following
When I run the following statement
The results would be:
What I want it to do is seperate the WHERE, LIMIT, and ORDER parts so that I can evaluate them later on in the code.
What seems to be the problem here? Am I doing anything wrong?
Thanks
I'm trying to use preg_match to match a particular SQL statement. The sql statement has to be in the following format:
1: The words SELECT followed by some text
2: The words FROM followed by some text following
3: (OPTIONAL) WHERE with some text following
4: (OPTIONAL) LIMIT with some text following
5: (OPTIONAL) ORDER with some text following
When I run the following statement
Code: Select all
$query = "SELECT (*) FROM ('school') WHERE id=0 LIMIT 0,10 ORDER id ASC";
preg_match('/SELECT (.+) FROM (.+)( WHERE (.+))?( LIMIT (.+))?( ORDER (.+))?/', $query, $m);Code: Select all
Array
(
[0] => SELECT (*) FROM ('school') WHERE id=0 LIMIT 0,10 ORDER id ASC
[1] => (*)
[2] => ('school') WHERE id=0 LIMIT 0,10 ORDER id ASC
)What seems to be the problem here? Am I doing anything wrong?
Thanks