Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要读取 xml 文件并将其内容加载到数组中。最简单的方法是什么?
$xml = json_decode(json_encode((array) simplexml_load_file("./test.xml")), 1); print_r $xml;
您可以尝试使用php 的SimpleXMLElement
$source = 'test.xml'; // load as string $xmlstr = file_get_contents($source); $xmlcont = new SimpleXMLElement($xmlstr); foreach($xmlcont as $url) { echo "{$url->loc} - {$url->lastmod} - {$url->changefreq} - {$url->priority}\r\n"; }
参考: http: //php.net/manual/en/class.simplexmlelement.php