나는 PHP의 간단한 XML 파서를 사용하는이 일에 갈 수있는 방법이라고 동의하시기 바랍니다. xpath
xml에서 데이터를 추출하는 방법을 사용하면 편리합니다. http://www.w3schools.com/xpath/
와 PHP 문서 그것을 여기 :
여기 XPath는 튜토리얼이있다 http://www.php.net/manual/en/simplexmlelement.xpath.php
<?php
/*
Get the file with CURL
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'ftp://ftp2.bom.gov.au/anon/gen/fwo/IDV10753.xml');
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,true);
$xml_data = curl_exec($curl_handle);
curl_close($curl_handle);
*/
/*
Open the file locally
*/
$xml_data = file_get_contents("weather.xml");
$xml = simplexml_load_string($xml_data);
$result = $xml->xpath("//area[@description='Swan Hill']/forecast-period");
date_default_timezone_set('America/New_York');
foreach ($result as $day) {
//print_r($day);
$day_of_the_week = date("l", strtotime($day["start-time-local"])); //start-time-local is an attribute of a result, so use the [] syntax
$forecast = $day->text; //text is a child node, so use the -> syntax
printf("%s: %s\n", $day_of_the_week, $forecast);
}
?>
편집 더 많은 예시를이 밖으로 시도
그럴 수 없어 'air_temperature_maximum'유형의 요소를 선택하는 방법 알아보기 이 도구를 사용해 보았지만 제대로 작동하지 못했습니다. $ max = $ day-> xpath ("element [@ type = 'air_temperature_maximum']"); 이 하나의 작품 : $ 분 = $ 하루 -> 요소 [1]; 하지만 필드 중 하나가 보이지 않는 경우 표시 할 항목을 올바르게 제어 할 수 없습니다. – Honshi