如何检查php中是否存在mcrypt扩展 [英] How to check if mcrypt extension exists in php

查看:278
本文介绍了如何检查php中是否存在mcrypt扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道最简单,最快的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:
由于我的答案仍会不时获得一些好评,因此我对我的表现和Cristi Draghici的答案进行了基准测试.结论是,function_existsextension_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆