PHP 检查扩展库或函数是否可用的代码
时间:2023-07-22 23:34:34
本文介绍的函数其实是PHP手册上本来就有的,但是由于这些函数独立性较强,查找不易,所以单独介绍一下,方便查阅。
1. 获取所有可用的模块 - get_loaded_extensions 该函数返回所有已经加载的(可用的)模块。
用法:
print_r(get_loaded_extensions());
2. 获取指定模块的可用函数 - get_extension_funcs 该函数返回指定模块所有可用的函数。传入的参数(模块名称)必须是小写
用法:
print_r(get_extension_funcs("gd"));
3. 获取所有已经定义的函数 - get_defined_functions 该函数返回所有已经定义的函数,包括内置函数和用户自定义函数。
用法:
function myrow($id, $data){
return "<tr><th>$id</th><td>$data</td></tr>\n";
}
$arr = get_defined_functions();
print_r($arr);
输出:
Array
(
[internal] => Array
(
[0] => zend_version
[1] => func_num_args
[2] => func_get_arg
[3] => func_get_args
[4] => strlen
[5] => strcmp
[6] => strncmp
...
[750] => bcscale
[751] => bccomp
)
[user] => Array
(
[0] => myrow
)
)
其中 $arr["internal"] 是内置函数, $arr["user"] 是用户自定义函数。
4. 检查指定函数是否存在 - function_exists 该函数返回指定函数是否已经定义。
用法:
if (function_exists('imap_open')) {
echo "IMAP functions are available.<br />\n";
} else {
echo "IMAP functions are not available.<br />\n";
}
标签:扩展库,函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python基于pyCUDA实现GPU加速并行计算功能入门教程
2021-11-01 08:24:58
![](https://img.aspxhome.com/file/2023/2/85332_0s.jpg)
BootstrapTable+KnockoutJS相结合实现增删改查解决方案(三)两个Viewmodel搞定增删改查
2024-04-28 09:36:56
![](https://img.aspxhome.com/file/2023/8/132858_0s.gif)
利用python为PostgreSQL的表自动添加分区
2023-07-07 14:44:58
php解析xml提示Invalid byte 1 of 1-byte UTF-8 sequence错误的处理方法
2023-09-09 18:55:22
keras 特征图可视化实例(中间层)
2021-12-05 22:54:46
![](https://img.aspxhome.com/file/2023/4/117924_0s.jpg)
Python *args和**kwargs用法实例解析
2023-01-16 18:30:55
python必备库Matplotlib画图神器
2021-03-29 21:16:08
![](https://img.aspxhome.com/file/2023/1/123461_0s.png)
简述Asp与XML之间的关系
2008-04-17 10:46:00
python 实现删除文件或文件夹实例详解
2021-03-23 03:16:37
JS将指定的某个字符全部转换为其他字符实例代码
2023-08-28 21:01:01
![](https://img.aspxhome.com/file/2023/3/56153_0s.png)
Windows10下安装配置 perl 环境的详细教程
2022-11-17 01:46:32
![](https://img.aspxhome.com/file/2023/0/65830_0s.jpg)
SQLServer2005混合模式登录配置(用户登录错误18452,233,4064)
2024-01-28 17:47:34
Golang测试框架goconvey进行单元测试流程介绍
2024-02-09 04:21:27
大容量SQL Server数据库迁移偏方
2011-05-05 08:18:00
详解PyTorch批训练及优化器比较
2023-08-23 11:52:54
![](https://img.aspxhome.com/file/2023/1/95481_0s.png)
python网络编程 使用UDP、TCP协议收发信息详解
2021-02-15 14:37:41
MySql数据库之alter表的SQL语句集合
2024-01-21 05:31:24
如何恢复数据库的账号 登录名/用户名等
2024-01-25 08:08:47
![](https://img.aspxhome.com/file/2023/4/91184_0s.png)
Python名片管理系统+猜拳小游戏案例实现彩(色控制台版)
2021-10-26 03:52:44
![](https://img.aspxhome.com/file/2023/9/108049_0s.gif)
解读unsafe.Pointer和uintptr的区别
2022-06-14 20:42:36
![](https://img.aspxhome.com/file/2023/1/97171_0s.png)