[PHP] Regular Expression help

  • Thread starter Thread starter Zom
  • Start date Start date

Zom

Zom

Associate
Joined
18 Oct 2002
Posts
1,117
I have a string which contains (amongst other things) information in the following format:

{center: {lat: 64.659779,lng: -7.376897}

Basically I'd like to be able to extract the lat/lng data but I can't figure out how to do it. Also, the lat and lng values range from xx.xxxxxx to -xx.xxxxxx. Could anyone show me how to create a regular expression to capture this info?
 
Code:
$lat = preg_replace('/^.*lat\: ([\-\.0-9]+),.*$/i', '$1', $string);
$long = preg_replace('/^.*lng\: ([\-\.0-9]+),/i.*$', '$1', $string);
untested.
 
Dj_Jestar said:
Code:
$lat = preg_replace('/^.*lat\: ([\-\.0-9]+),.*$/i', '$1', $string);
$long = preg_replace('/^.*lng\: ([\-\.0-9]+),/i.*$', '$1', $string);
untested.
Thanks, that works a treat. Just had to make one small change:
$lat = preg_replace('/^.*lat\: ([\-\.0-9]+),.*$/i', '$1', $string);
$long = preg_replace('/^.*lng\: ([\-\.0-9]+),.*$/i', '$1', $string);
 
Back
Top Bottom