PHP XML解析
- Category:
- PHP
// xmlファイルへのパス
$top_xml_file = PATH TO XML FILE;
// ファイル内容を取得
$contents = file_get_contents($top_xml_file);
// やりかた1
$xml = simplexml_load_string($contents);
print_r($xml);
// やりかた2
$xml_parser=xml_parser_create();
xml_parse_into_struct($xml_parser,$contents,$vals);
xml_parser_free($xml_parser);
print_r($vals);
// やりかた3
$options = array('complexType' => 'array');
$Unserializer =& new XML_Unserializer($options);
$Unserializer->setOption('parseAttributes', true);
$status = $Unserializer->unserialize($contents);
$data = $Unserializer->getUnserializedData();
print_r($data);