0

KMLファイルを解析して配列に入れたいので、より良い方法でその要素にアクセスできます。PHPでXML形式で解析する必要がありますか?

4

2 に答える 2

1

次のようになります。

function parseKML1(){
    $contents = file_get_contents('cotest.kml'); // filename
 $xml      = new SimpleXMLElement($contents);  //getting the contents
 $value    = (string)$xml->Document->Folder->Placemark->Polygon->outerBoundaryIs->LinearRing->coordinates; ///KML Structure
 $values   = explode(" ", trim($value));
 $coords   = array();
 foreach($values as $value) {    
    $args     = explode(",", $value);
    $coords[] = array($args[0], $args[1],$args[2]);
 }

 echo('<pre>');
 print_r($coords);  //printing the array

 }

それが、phpでデータを配列に解析する方法です

<kml><Document><Folder><name>sql_statement</name><Schema name="sql_statement" id="sql_statement"></Schema><Placemark><name>Hall                                                                                      </name><ExtendedData></ExtendedData><Polygon><outerBoundaryIs><LinearRing><coordinates>-100.944938999999906,34.748280999999963,0 -100.84772799999989,34.748310999999966,0 -100.655293999999884,34.748058999999962,0 -100.600692999999907,34.747958999999966,0 -100.572734999999895,34.747869999999963,0 -100.555416999999892,34.747772999999967,0 -100.54070299999988,34.747722999999965,0 -100.523008999999888,34.747637999999966,0 -100.415894999999907,34.747524999999968,0 -100.415911999999906,34.590452999999961,0 -100.415797999999882,34.561719999999966,0 -100.415795999999887,34.561262999999961,0 -100.415880999999899,34.528678999999961,0 -100.415949999999896,34.517005999999967,0 -100.415949999999896,34.515623999999967,0 -100.41773099999989,34.362238999999967,0 -100.417782999999901,34.313523999999965,0 -100.498192999999901,34.313526999999965,0 -100.503372999999897,34.314078999999964,0 -100.517339999999891,34.314101999999963,0 -100.624037999999899,34.314191999999963,0 -100.625403999999904,34.313398999999961,0 -100.627353999999897,34.313391999999965,0 -100.672836999999888,34.313473999999964,0 -100.682781999999904,34.313389999999963,0 -100.693753999999885,34.313298999999965,0 -100.721133999999893,34.313324999999963,0 -100.723279999999903,34.313318999999964,0 -100.728890999999891,34.313304999999964,0 -100.766540999999904,34.313280999999968,0 -100.769850999999903,34.313256999999965,0 -100.897068999999888,34.312961999999963,0 -100.897904999999895,34.313171999999966,0 -100.897904999999895,34.313034999999964,0 -100.919962999999882,34.312879999999964,0 -100.946161999999887,34.312762999999961,0 -100.94604099999988,34.314444999999964,0 -100.946118999999882,34.333875999999961,0 -100.946152999999896,34.338639999999963,0 -100.946345999999892,34.370078999999961,0 -100.945927999999896,34.379509999999968,0 -100.945818999999901,34.386378999999963,0 -100.945465999999897,34.483357999999967,0 -100.945461999999893,34.484496999999962,0 -100.945575999999903,34.491797999999967,0 -100.9455379999999,34.492196999999962,0 -100.945423999999903,34.494767999999965,0 -100.945156999999895,34.622261999999964,0 -100.945175999999904,34.627944999999961,0 -100.945176999999887,34.630168999999967,0 -100.944938999999906,34.748280999999963,0</coordinates>
于 2012-11-07T12:36:02.193 に答える