Need Help with PHP and REGEX
Posted: Mon Feb 15, 2010 11:40 pm
Hello, I have this script:
Which returns:
I would like for $results to contain only "ST.+JOHN%27S%2C+NL"; in other words the city name and the province/state for the visiting user.
Unfortunately my experience with PHP REGEX is little to none and I've tried hard to make this work before posting here but my attempts were unsuccessful
Any help would be greatly appreciated. Thanks
Code: Select all
<?php
function getLocation() {
$ip = $_SERVER['REMOTE_ADDR'];
$geo = file_get_contents("http://api.hostip.info/get_html.php?ip=$ip");
$results = urlencode($geo);
echo $results;
}
getLocation();
?>
Code: Select all
Country%3A+CANADA+%28CA%29%0ACity%3A+ST.+JOHN%27S%2C+NL%0AIP%3A+142.162.13.207%0A
Unfortunately my experience with PHP REGEX is little to none and I've tried hard to make this work before posting here but my attempts were unsuccessful
Any help would be greatly appreciated. Thanks