[Solved] How to parse xml with php? [duplicate]


You can use SimpleXML_Load_String.

<?php // RAY_temp_burhan.php
error_reporting(E_ALL);
echo '<pre>';

$xml = <<<ENDXML
<?xml version="1.0" encoding="ISO-8859-1" ?>
<eqlist>
    <earhquake  name="2012.12.31 18:35:13"  lokasyon="CAMONU-AKHISAR (MANISA)                           Ilksel" lat="38.9572"   lng="27.8965"   mag="2.9" Depth="5.0" />
    <earhquake  name="2012.12.31 18:54:09"  lokasyon="VAN GÖLÜ                                          Ilksel" lat="38.7273"   lng="43.1598"   mag="2.3" Depth="2.1" />
    <earhquake  name="2012.12.31 21:00:49"  lokasyon="KUCUKESENCE-ERENLER (SAKARYA)                     Ilksel" lat="40.7347"   lng="30.4742"   mag="1.9" Depth="4.4" />
</eqlist>
ENDXML;

// CONVERT TO AN OBJECT
$obj = SimpleXML_Load_String($xml);

// PARSE OUT SOME ATTRIBUTES
foreach ($obj as $quake)
{
    // ATTRIBUTE NAMES ARE CASE-SENSITIVE
    $loc = $quake->attributes()->lokasyon;
    $dep = $quake->attributes()->Depth;
    echo PHP_EOL . "$loc $dep";
}

6

solved How to parse xml with php? [duplicate]