This way the modified data (ie. "City%2C+State") gets passed off into $results.
I need $results encoded because this script is going to be part of another script where $results get passed off as part of a URL parameter.
Regex seems to work differently with PHP, and I don't have much experience with regex or arrays; I'm just learning as I go
Any help would be greatly appreciated. Thanks
Before using preg_match() on your $results, one approach would be split your $results into an array using the "+" delimiter that is in the $results string first.
$my_part[0]= Country
$my_part[1]= CANADA+%28CA%29%0ACity
$my_part[2]= ST.+JOHN%27S%2C+NL%0AIP
$my_part[3]= 142.162.13.207%0A
If you explode() twice, I think you can get the substrings you are looking for without preg_match(), then combine them, of course. Or you can simply preg_replace() the offending "IP" with "" at the end of $my_part[2] ... up to you.
It might work for you to simply explode() on "%3A" first, it's up to you (not sure of your final output.. but it seems "%3A+" is best). Your string:
$my_part[0]= Country
$my_part[1]= +CANADA+%28CA%29%0ACity
$my_part[2]= +ST.+JOHN%27S%2C+NL%0AIP
$my_part[3]= +142.162.13.207%0A
Hopefully, I did not make too many "cut and paste" errors in my examples!