Hello I was hoping somebody can help me out with this Regular Expression I am trying to correctly formulate.
I have some urls like these:
file.ext?var1=something&var2=something+else etc etc
one of the vars is called city and contains values such as:
Los Angeles
Toronto
Houston, TX
Philadelphia PA
Because they are already urlencoded they look like this:
Los+Angeles
Toronto
Houston,+TX (which really is Houston%2C+TX, because the comma is %2C)
Philadelphia+PA
I need to remove all the states from those variables that contain a state, and if they also have a comma and/or a space between the city and the state I need to remove that one too.
I have a preg_replace with a search array and a replace array and my the part that is supposed to do this I wrote out like this:
"'\&city\=(.?)(%2C)?+(.?)\&'si"
to be replaced by:
"&city=$1&"
Obviously something is wrong because it also seems to be true whenever it finds a plus sign which is not what I wanted.
In my mind I had imagined that that search string would translate into:
search for whatever is between '&city=' and '&', where there might be zero or one comma (%2C) and one plus sign.
What did I do wrong?
Thanks for your suggestions.