Solved

parsing php string for lat and long

Posted on 2007-03-29
3
410 Views
Last Modified: 2008-03-06
Im using an http request to get data that looks like this.

$xml = map.centerAndZoom(new GPoint(-82.81649, 42.175552), 4);

how can I parse this string to get the lat and long only.

$lat =
$long =
0
Comment
Question by:jimfrith
3 Comments
 
LVL 24

Accepted Solution

by:
glcummins earned 500 total points
ID: 18818373
This is not a fancy regex, but you can get what you need using strpos and strrpos:

<?php

$xml = "map.centerAndZoom(new GPoint(-82.81649, 42.175552), 4)";

$start = 1+strrpos($xml, '(');
$end = strpos($xml, ')');

list($latitude, $longitude) = explode(', ', substr($xml, $start, ($end-$start)));

echo "Latitude: $latitude<br />";
echo "Longitude: $longitude<br />";

?>
0
 

Author Comment

by:jimfrith
ID: 18818416
thanks for that
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 18818622
In case the string position changes, you can try this:

<?
$str = '$xml = map.centerAndZoom(new GPoint(-82.81649, 42.175552), 4);';
$m = "/GPoint\(([\-0-9.]+), ([\-0-9.]+)\)/";
$a=array();
preg_match($m, $str, $a);
print_r($a);
?>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now