Cannot read XML file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mbratu74
Forum Newbie
Posts: 1
Joined: Wed Jan 31, 2018 9:36 am

Cannot read XML file

Post by mbratu74 »

I have a php file called from html page. this file need to read a local xml file and return an array with data...
I tried many version of code but when i tried to open the file the page go in error without the possibility to check the error. The only command that work is $xml_string= file_get_contents('Stations.xml');
Any other like :
simplexml_load_string($xml_string);
simplexml_load_file("Stations.xml");
does not work...

The flag allow_open_url is ON...

Someone have an idea about what is happened...

Thanks in advance
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Cannot read XML file

Post by Christopher »

Where is the file "Stations.xml"? The could should probably be:

Code: Select all

simplexml_load_file('/full/file_system/path/to/Stations.xml');
* replace '/full/file_system/path/to/' with the actual path to the directory containing the XML file.
(#10850)
pardeeptrivedi
Forum Newbie
Posts: 5
Joined: Tue Feb 06, 2018 1:33 am

Re: Cannot read XML file

Post by pardeeptrivedi »

<?php
// The file test.xml contains an XML document with a root element
// and at least an element /[root]/title.

if (file_exists('test.xml')) {
$xml = simplexml_load_file('test.xml');

print_r($xml);
} else {
exit('Failed to open test.xml.');
}
?>
Post Reply