Solved

parsing php string for lat and long

Posted on 2007-03-29
3
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

730 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