How to check if mcrypt extension exists in php

后端 未结 3 998
野性不改
野性不改 2021-02-13 17:28

I would like to know the simplest and fastest PHP code line to check if mcrypt extension is available/installed.

There is a function that encrypts a string and first it

3条回答
  •  无人共我
    2021-02-13 17:43

    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!";
    }
    

    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

提交回复
热议问题