如何测试我的 PHP 上是否安装了 SimpleXML?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6774581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:12:53  来源:igfitidea点击:

How to Test Whether SimpleXML is installed on my PHP or not?

phpmysqlvb.net

提问by Anonymous White

Anyone 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

我检查 simplexml_load_string 是否对我可用,但是如何在 php.ini 中未列出 simplexml

回答by Srinath

There is another way also. You can create a php page

还有另一种方式。你可以创建一个php页面

    <?php
     echo phpinfo();
    ?>

You can see Simple XML enabled or disabled here.

您可以在此处查看启用或禁用 Simple XML。

回答by Beard of Binary

This works for me...

这对我有用...

extension_loaded('simplexml')

example:

例子:

if (extension_loaded('simplexml')) {

    echo "all good, extension is installed";

} else{ echo "snip snap! no cigar";}    

回答by chris

Use this command on the commandline:

在命令行上使用此命令:

php -i | grep -i simplexml

php -i | grep -i simplexml

The result should be something like this:

结果应该是这样的:

SimpleXML

Simplexml support => enabled

简单XML

Simplexml 支持 => 启用

回答by James Butler

If you have command line access on your box; either use your OS's package management system, or run php -mwhich 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.

如果您的机器上有命令行访问权限;要么使用操作系统的包管理系统,要么运行php -m它,它应该列出 PHP 知道的所有已安装模块。任何已安装但未在 php.ini 或其他任何地方注册为扩展名的模块都不会显示。

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

应该注意的是,运行此命令只会告诉您为 PHP 的 CLI 二进制文件/配置启用了哪些扩展。这通常(但可能并不总是)与 Apache/FPM 二进制文件/配置已启用的内容相匹配

回答by p2s

One solution i use :

我使用的一种解决方案:

if(class_exists('XMLReader')){

}elseif(function_exists('simplexml_load_file')){
//simplexml available
}else{

}

回答by Cups

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.

这将显示一个扩展列表。如果您希望您的应用程序巧妙地告诉您的用户他们的设置不会运行您的代码,那么只需使用 in_array() 。

EDIT This is the case on 5.2.6 on win32 anyway.

编辑无论如何,win32 上的 5.2.6 就是这种情况。