php通过function_exists检测函数是否存在的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php通过function_exists检测函数是否存在的方法。分享给大家供大家参考。具体分析如下:

php中可以通过function_exists()函数检测另外一个函数是否存在,可以把函数名作为一个字符串传入function_exists,判断该还是是否存在

function highlight( $txt ) {
  return "<sub>$txt</sub>";
}
function textWrap( $tag, $txt, $func="" ) {
 if (function_exists( $func ) )
  $txt = $func($txt);
  return "<$tag>$txt</$tag>\n";
}

用法示例如下:

echo textWrap('i','function exists Demo','highlight');
//输出结果为斜体字的: function exists Demo

希望本文所述对大家的php程序设计有所帮助。

相关文章

php 全局变量范围分析

复制代码 代码如下: <?php $a = 1 ; include 'b.inc' ; ?> 这里变量 $a 将会在包含文件 b.inc 中生效。但是,在用户自定义函数中,...

php array 转json及java 转换 json数据格式操作示例

本文实例讲述了php array 转json及java 转换 json数据格式操作。分享给大家供大家参考,具体如下: php array 转json 数据 $arr = array(...

php简单复制文件的方法

本文实例讲述了php简单复制文件的方法。分享给大家供大家参考,具体如下: <?php /** *author:果冻 *qq:52091199 *wyg517.blog....

PHP遍历目录并返回统计目录大小

复制代码 代码如下: <?php $dirname = "test1"; //mkdir($dirname); //遍历一层目录 function listdir($dirname...

PHP工厂模式的日常使用

负责生成其他对象的类或方法,这就是工厂模式,下面是一个经常见到的用法 <?php class test{ public $x=1; public $settin...