How to Test Whether SimpleXML is installed on my PHP or not?
Anyo开发者_开发技巧ne knows that? That thing is installed by default. But is there an easy way to check whether an extension is installed or not?
I check that simplexml_load_string is available to me but how do simplexml is not listed on php.ini
There is another way also. You can create a php page
<?php
echo phpinfo();
?>
You can see Simple XML enabled or disabled here.
This works for me...
extension_loaded('simplexml')
example:
if (extension_loaded('simplexml')) {
echo "all good, extension is installed";
} else{ echo "snip snap! no cigar";}
Use this command on the commandline:
php -i | grep -i simplexml
The result should be something like this:
SimpleXML
Simplexml support => enabled
If you have command line access on your box;
either use your OS's package management system, or run php -m
which should list all installed modules which PHP is aware of.
Any module which has been installed but is not registered as extension in php.ini or anywhere else will not show up.
EDIT
It should be noted that running this command will only tell you what extensions are enabled for the CLI binary/config of PHP. This generally is, but may not always be, match up with what the Apache/FPM binary/config has enabled
One solution i use :
if(class_exists('XMLReader')){
}elseif(function_exists('simplexml_load_file')){
//simplexml available
}else{
}
echo '<pre>';
print_r( get_loaded_extensions());
echo '</pre>';
That will show you a list of extensions. Then just use in_array() if you want your application to smartly tell your users that their setup will not run your code.
EDIT This is the case on 5.2.6 on win32 anyway.
精彩评论