|
-
Feb 15th, 2007, 10:11 AM
#1
Thread Starter
Hyperactive Member
How to split this information? (code included)
I'm working with GEO IP, I can display the information, please see the below code and notes.
Code:
<?PHP
$ipaddress = $_SERVER['REMOTE_ADDR'];
$license_key = "PRIVATE";
$query = "http://maxmind.com:8010/f?l=" . $license_key . "&i=" . $ipaddress;
$url = parse_url($query);
$host = $url["host"];
$path = $url["path"] . "?" . $url["query"];
$timeout = 1;
$fp = fsockopen ($host, 8010, $errno, $errstr, $timeout)
or die('Can not open connection to server.');
if ($fp) {
fputs ($fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n");
while (!feof($fp)) {
$buf .= fgets($fp, 128);
}
$lines = split("\n", $buf);
$data = $lines[count($lines)-1];
fclose($fp);
} else {
//echo "uh oh";
}
echo $data;
?>
The code outputs this information for me:
US,NY,Ithaca,,42.427799,-76.498199,555,607,"Road Runner","Road Runner"
I would ONLY like to display the "607", US, NY, Ithaca in different places on my page.
So If someone could help me split this information that would be great.
On my page I want to display the information as:
Ithaca, NY - US
and 607 (area code) will be displayed in a completely different location so I would like to be able to put this code anywhere on my site to display the area code:
Code:
<?PHP echo $areacode; ?>
In fact I'd like to do that with all information.
Code:
<?PHP echo $city; ?>
Code:
<?PHP echo $country; ?>
thank you!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|