Allright, I'm working with some Google Maps crap with Zip codes and all. There's a site called GeoCoder.Us that allows you to look up places and get the Lat/Long.
With that being said, you can use a custom URL with the zipcode to get that particular Lat/Long info:
Ex: Go to this URL...: http://geocoder.us/service/csv/geocode?zip=95472
...and it will give you this string of text:
38.393314, -122.83666, Sebastopol, CA, 95472
I want to take the returned string of text above and chop everything after the second "," off so that I just end up with: 38.393314, -122.83666
That way I can plug it into Google Maps using a variable.
Any ideas? I just need the PHP code to chop off everything that second "," comma everytime. Thanks.
Editing data in PHP
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
How about:
Code: Select all
$str = '38.393314, -122.83666, Sebastopol, CA, 95472';
$fields = explode(',', $str);
$position = $fields[0] . ',' . $fields[1];(#10850)
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
function getCoordinates($zip) {
$content = file_get_contents('http://geocoder.us/service/csv/geocode?zip='.$zip);
$coordinates = explode(',' $content);
if (count($coodinates)) {
return array($coordinates[0], $coordinates[1]);
}
}
echo getCoordinates(90210);Your code seems to work, but I'm getting an error trying to use it.Jcart wrote:Code: Select all
function getCoordinates($zip) { $content = file_get_contents('http://geocoder.us/service/csv/geocode?zip='.$zip); $coordinates = explode(',' $content); if (count($coodinates)) { return array($coordinates[0], $coordinates[1]); } } echo getCoordinates(90210);
Parse error: parse error, unexpected T_VARIABLE in /var/www/tags/test.php on line 4
Odd. Any other workarounds?