troubleshooting Question

RegExp to extrct longitude and latitude from a string

Avatar of Doomish
Doomish asked on
Regular ExpressionsPHP
3 Comments1 Solution10 ViewsLast Modified:
I inherited a database with a location field that contains data in the following style:

a:3:{s:7:"address";s:32:"Belgrade, Serbia";s:3:"lat";s:10:"44.8234945";s:3:"lng";s:17:"20.46218669999996";}
a:3:{s:7:"address";s:30:"Los Angeles, CA, United States";s:3:"lat";s:10:"34.0522342";s:3:"lng";s:12:"-118.2436849";}
a:3:{s:7:"address";s:58:"Wauwatosa, United States";s:3:"lat";d:43.05008220000001;s:3:"lng";d:-87.9901927;}
a:3:{s:7:"address";s:32:"London, England";s:3:"lat";d:51.4743113;s:3:"lng";d:-0.1010046;}

The data in the field varies, but what is constant in all of them is the last part of the string: "lat";d:51.4743113;s:3:"lng";d:-0.1010046;}
I would like to clean them up and extract only the lat and lng from the string from the above and echo them like:

Coordinates: 51.4743113,-0.1010046

Any help is appreciated, many thanks!

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros