Jump to content

parsing xml with php


ishboo

Recommended Posts

So I have this xml parser that works fine and my xml file has this:

<wpt lat="39.6512" lon="-84.147733">
    <time>2006-01-24T00:00:00.0000000-08:00</time>
    <name>GCZF70</name>

The part in my parser that sets where to look in the structure is:

$xml_name_key = "*GPX*WPT*NAME";

When I use the above setting, it works correctly so I know the program works, but how would I get the lat and lon values from the <wpt> tag? I tried *GPX*WPT*LAT also *GPX*WPT:lat *GPX*WPT *GPX*WPT-lat none of them worked, how should I code it properly?

Link to comment
https://forums.phpfreaks.com/topic/56961-parsing-xml-with-php/
Share on other sites

<?php

$string = "<wpt lat=\"39.6512\" lon=\"-84.147733\">\n    <time>2006-01-24T00:00:00.0000000-08:00</time>\n    <name>GCZF70</name>";

preg_match("/lat=\"([\d.]+)/", $string, $matches);

list($full, $lat) = $matches;

preg_match("/lon=\"([\d.-]+)\"/", $string, $matches);

list($full, $lon) = $matches;

unset($full);

echo "Lat: {$lat}<br />\nLon: {$lon}";

?>

 

Try that, untested.

Link to comment
https://forums.phpfreaks.com/topic/56961-parsing-xml-with-php/#findComment-281366
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.