如何检查php上是否存在mcrypt扩展名 [英] How to check if mcrypt extension exists on php
问题描述
我想知道最简单和最快的PHP代码行,以检查是否可以/安装了mcrypt扩展。
I would like to know the simplest and fastest PHP code line to check if mcrypt extension is available/installed.
有一个函数加密一个字符串,第一个它需要检查mcrypt是否可用。如果没有,它将执行系统上可用的备用加密解决方案。
There is a function that encrypts a string and first it requires to check if mcrypt is usable. If not, it will execute an alternative encrypt solution available on the system.
谢谢!
推荐答案
您可以使用 function_exists
来检查其中一个mcrypt函数是否存在。
You can use function_exists
to check if one of the mcrypt functions exists.
if(function_exists('mcrypt_encrypt')) {
echo "mcrypt is loaded!";
} else {
echo "mcrypt isn't loaded!";
}
编辑30.07.2016:
由于我的答案还是得到了不时的升华,我评估了我的表现和克里斯蒂·德拉吉奇的答案。结论是, function_exists
比 extension_loaded
快一点。 https://3v4l.org/So4Ep
Edit 30.07.2016:
Since my answer still gets a few upvotes from time to time, I benchmarked the performance of mine and Cristi Draghici's answers. The conclusion is, that function_exists
is a bit faster than extension_loaded
. https://3v4l.org/So4Ep
这篇关于如何检查php上是否存在mcrypt扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!