I have the following code (from a previous question on this site) which retrieves a certain image from an XML file:
$xml = simplexml_load_file('path/to/file');
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);
You can use simplexml_load_file