[RESOLVED] Test for simplexml_load_file() support?
Code:
/* INITIALIZE THE XML FILE */
$xml_file=@simplexml_load_file('path/to/my/file.txt');
/* PERFORM AN ERROR TEST */
if($xml_file) {
/* LOOP THROUGH THE XML */
foreach($xml_file->xml_tag AS $tag) {
/* THE ARRAY */
// here i fill the array elements
/* INCREMENT THE VARIABLE */
$i+=1;
}
} else {
// my alternate code
// parse it another way...
}
Hello all.
Is there a way of determining whether or not a server supports simplexml, and if it does not, then go to my alternate code?
Thanks in advance.
Re: Test for simplexml_load_file() support?
A call to undefined function always throws a fatal error in PHP. Fatal errors cannot be caught so your best option is to test it exists first. Use the extension_loaded / function_exists function:
PHP Code:
if (extension_loaded("simplexml")) {
}
// OR
If (function_exists("simplexml_load_file")) {
}
Also, if you are using PHP 4 simple XML will not be available you can test this with the phpversion function too. The simplest way is - function_exists.
Re: Test for simplexml_load_file() support?
Beautiful. Thanks again VisualAd.