Hi,
I'm trying to replace all characters between two words in a string. If someone could help me out it would be much appreciated.
This is what I want to do:
$sString1 = " select field, field2, field 3
from table
where field1 = 'something'
union(
select field, field 2, field 3
from table
where field2 = 'somethingelse'
)";
See how there are two select clauses in the query? Well what I want to do is replace both with "select count(*) from"
This is what the first string should look like after I perform the replace:
$sString2 = " select count(*)
from table
where field1 = 'something'
union(
select count(*)
from table
where field2 = 'somethingelse'
)";
So, how can I make the 1st string equal the 2nd string using regular expressions?
I can't seem to find a way to Not find a word. Because the only way I can think of doing it is replacing 'select' and all words that are not 'from' up untill I come to the word 'from'.
How do I do this?
I've been trying things like this to no avail:
$sSQL = preg_replace("/select(.*)from/is","select count(*) from",$sSQL);
But that will of course not work as it will eat up the first 'from' and go untill it reaches the last 'from'
Why is it there is a ^ for negating a single character in a class [] blut not a way to negate a whole series of characters? Or is there?
I hate regular expressions!
If you can help that would be great.
Thanks.
-Adam 🙂