這篇文章主要介紹了php通過function_exists檢測函數是否存在的方法,實例分析了php使用function_exists檢測函數是否存在及調用的相關技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了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
新聞熱點
疑難解答