Solarpitch Posted May 30, 2011 Share Posted May 30, 2011 Hi Guys, I'm trying to run the following code but the page breaks with no errors. I'm using PHP 5 which should run Simple XML. Code seems fine to me... <?php $xmlstr = "courses.xml"; $xml = new SimpleXMLElement($xmlstr); // I Know it's breaking at this line echo $xml->course[0]->name; ?> Link to comment https://forums.phpfreaks.com/topic/237885-simplexmlelement-issue/ Share on other sites More sharing options...
.josh Posted May 30, 2011 Share Posted May 30, 2011 php doesn't just stop running or "breaking" as you say, without a reason (without an error). If it is because of an error, you must have error reporting turned off in php.ini or .htaccess or somewhere. edit: also, are you sure that 3rd line of code is even returning anything? Link to comment https://forums.phpfreaks.com/topic/237885-simplexmlelement-issue/#findComment-1222412 Share on other sites More sharing options...
Solarpitch Posted May 30, 2011 Author Share Posted May 30, 2011 The 3rd line doesnt return anything.. I added echo "Test" after the 2nd line and it didnt print so I know it's throwing an error there. Dunno why error_reporting is off.. trying to see where it's turned off Link to comment https://forums.phpfreaks.com/topic/237885-simplexmlelement-issue/#findComment-1222418 Share on other sites More sharing options...
Solarpitch Posted May 30, 2011 Author Share Posted May 30, 2011 Ok, got the error.. Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found in /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php on line 50 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: http://site.mysite.ie/wp-content/themes/iact/courses.xml in /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php on line 50 Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php on line 50 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php:50 Stack trace: #0 /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php(50): SimpleXMLElement->__construct('http://site.iac...') #1 /var/www/vhosts/httpdocs/wp-includes/template-loader.php(43): include('/var/www/vhosts...') #2 /var/www/vhosts/httpdocs/wp-blog-header.php(16): require_once('/var/www/vhosts...') #3 /var/www/vhosts/httpdocs/index.php(17): require('/var/www/vhosts...') #4 {main} thrown in /var/www/vhosts/httpdocs/wp-content/themes/iact/page.php on line 50 Link to comment https://forums.phpfreaks.com/topic/237885-simplexmlelement-issue/#findComment-1222444 Share on other sites More sharing options...
.josh Posted May 30, 2011 Share Posted May 30, 2011 okay, so it looks like your courses.xml file is mal-formed. You need to make sure the xml file is properly formatted. Link to comment https://forums.phpfreaks.com/topic/237885-simplexmlelement-issue/#findComment-1222447 Share on other sites More sharing options...
Solarpitch Posted May 30, 2011 Author Share Posted May 30, 2011 Actually, found the solution... If you are passing it a filename instead of a string, the third parameter needs to be TRUE, e.g.: $sxe = new SimpleXMLElement('they_wont_let_me_put_a_url_here', NULL, TRUE); Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/237885-simplexmlelement-issue/#findComment-1222450 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.