Load external xml file?

前端 未结 3 1499
粉色の甜心
粉色の甜心 2021-01-13 10:00

I have the following code (from a previous question on this site) which retrieves a certain image from an XML file:



        
相关标签:
3条回答
  • 2021-01-13 10:21

    $xml = simplexml_load_file('path/to/file');

    0 讨论(0)
  • 2021-01-13 10:28

    Procedurally, simple_xml_load_file.

    $file = '/path/to/test.xml';
    if (file_exists($file)) {
        $xml = simplexml_load_file($file);
        print_r($xml);
    } else {
        exit('Failed to open '.$file);
    }
    

    You may also want to consider using the OO interface, SimpleXMLElement.

    Edit: If the file is at some remote URI, file_exists won't work.

    $file = 'http://example.com/text.xml';
    if(!$xml = simplexml_load_file($file))
      exit('Failed to open '.$file);
    print_r($xml);
    
    0 讨论(0)
  • 2021-01-13 10:34

    You can use simplexml_load_file

    0 讨论(0)
提交回复
热议问题