thdim Posted March 26, 2008 Share Posted March 26, 2008 Hello Everybody, In my code I use the SimpleXMLElement object to handle some RSS files like this: $xml = new SimpleXMLElement($feedurl, NULL, true); and it works perfect BUT when there is any problem with the $feedurl (like url change) the SimpleXMLElement crashes with a Fatal Error and that destroys my application flow. Is there any way to avoid SimpleXMLElement crashing? any ideas? p.s. I've tried using $xml = @new SimpleXMLElement($feedurl, NULL, true); but without success. thanks, Link to comment https://forums.phpfreaks.com/topic/98069-simplexmlelement-avoid-fatal-error/ Share on other sites More sharing options...
Barand Posted March 26, 2008 Share Posted March 26, 2008 if ($xml = simplexml_load_file ('my.xml') ) { // process $xml } else { //error } Link to comment https://forums.phpfreaks.com/topic/98069-simplexmlelement-avoid-fatal-error/#findComment-501772 Share on other sites More sharing options...
thdim Posted March 26, 2008 Author Share Posted March 26, 2008 Ok I solve the problem with the use of simplexml_load_string(), first open the file with fopen read the contents with stream_get_contents and then sent the string to simplexml_load_string. Link to comment https://forums.phpfreaks.com/topic/98069-simplexmlelement-avoid-fatal-error/#findComment-501774 Share on other sites More sharing options...
Barand Posted March 26, 2008 Share Posted March 26, 2008 Wow, that sounds easier than simplexml_load_file Link to comment https://forums.phpfreaks.com/topic/98069-simplexmlelement-avoid-fatal-error/#findComment-501776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.