PHP - Extract XML data to a 2d array



I was wondering if someone could give me a hand.


I have a KML file ( Google Maps XML ) ... I need to extract the coordinates to a 2D array.


The format of the file is as follows:



<?xml version="1.0" encoding="UTF-8"?>
<kml
xmlns="http://ift.tt/1b6BtQH">
<Document>
<Placemark>
<name>Im a name</name>
<Point>
<coordinates>138.611798,-34.926053</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Im a name</name>
<Point>
<coordinates>138.611798,-34.926053</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Im a name</name>
<Point>
<coordinates>138.611798,-34.926053</coordinates>
</Point>
</Placemark>
[...]


I need to be able to return an array with the following format



Array
(
[0] => Array
(
[0] => 138.611798
[1] => -34.926053
)
[1] => Array
(
[0] => 138.611798
[1] => -34.926053
)


My kml file will contain quite a few points so i need to be able to do this automatically.


Any help would be really appreciated.


Thanks


No comments:

Post a Comment