Regular Expression help
Posted: Mon Dec 06, 2004 4:12 pm
I am working with the preg_replace function and I can't seem to get the variable trimmed quite right. We solved the problem as long as the PHP script is run for my town always, but we want to use it in other locations as well.
The data inside the variable (I call $location) is as follows:
Shawnee, KS (66214)
We want to loose the space and (66214)... the code I tried is this:
This makes the following output:
Shawnee, KS ()
I am not sure being as I am not good at defining regular expressions, can someone tell me what is wrong with my replace command.
earlier someone suggested that I use str_replace but that will break whenever we change the zipcode of the weather XML feed.
Thanks,
The data inside the variable (I call $location) is as follows:
Shawnee, KS (66214)
We want to loose the space and (66214)... the code I tried is this:
Code: Select all
$location = preg_replace(' (ї0-9+])','', $location);
$location = trim($location);Shawnee, KS ()
I am not sure being as I am not good at defining regular expressions, can someone tell me what is wrong with my replace command.
earlier someone suggested that I use str_replace but that will break whenever we change the zipcode of the weather XML feed.
Thanks,