十三郎的IT生活

 

PHP中检查库或函数是否可用的方法

本文介绍的函数其实是PHP手册上本来就有的,但是由于这些函数独立性较强,查找不易,所以单独介绍一下,方便查阅。

1. 获取所有可用的模块 - get_loaded_extensions

<?php
print_r
(get_loaded_extensions());
?>

2. 获取指定模块的可用函数 - get_extension_funcs

<?php
print_r
(get_extension_funcs("mysql"));
?>

3. 获取所有已经定义的函数 - get_defined_functions

<?php
function myrow($id, $data)
{
     return
"<tr><th>$id</th><td>$data</td></tr>\n";
}
    
$arr = get_defined_functions();
    
print_r($arr);
?>

其中 $arr["internal"] 是内置函数, $arr["user"] 是用户自定义函数。

4. 检查指定函数是否存在 - function_exists
该函数返回指定函数是否已经定义。

<?php
if (function_exists('imap_open'))
{
     echo
"IMAP functions are available.<br />\n";
} else {
     echo
"IMAP functions are not available.<br />\n";
}
?>

posted on 2009-05-13 11:31 十三郎 阅读(285) 评论(0)  编辑 收藏 引用 所属分类: 语言

只有注册用户登录后才能发表评论。

导航

常用链接

留言簿(5)

随笔分类

文章分类

积分与排名