Reputation: 2422
My code just returns this:
Fatal error: Call to undefined function SimpleXMLElement() in /path/to/xmltest.php on line 6
And the code itself:
<?php
$language_url = "http://www.fakesite.com/api/FAKEAPIKEY/languages.xml";
// Passing the XML
$data = file_get_contents($language_url);
$books = SimpleXMLElement($data);
//-------------------
// Passing a filename
//$books = SimpleXMLElement($language_url, null, true);
?>
Naturally, $language_url
is valid, but I changed it for privacy concerns. It resides on a different site from which I'm trying to run this script.
Upvotes: 0
Views: 7555
Reputation: 47321
SimpleXMLElement
is a class for simplexml,
you should instantiate it like the usual object :-
$books = new SimpleXMLElement($data);
Or the procedural function
$books = simplexml_load_string($data); // load from string
$books = simplexml_load_file($url); // load from file
Upvotes: 6
Reputation: 2042
Is the SimpleXML library loaded? Look throu your php.ini for a line saying ;extension=simplexml.so
and remove the semicolon. Restart your http service and it should work.
Upvotes: 2