function_exists

function_exists是用來檢查指定的函式是否已經定義的函式。

基本介紹

  • 中文名:function_exists
  • 作用:用來檢查指定的函式是否已經定義
定義和用法,語法,例子,實例,作用,註解,
boolean function_exists (string function_name),本函式用來檢查指定的函式是否已經定義。

定義和用法

boolean function_exists (string function_name),本函式用來檢查指定的函式是否已經定義。參數 function_name 為待檢查的函式名稱。若已定義指定的函式則返回1 值,其它情形均返回 0 值。

語法

function_exists(string function_name)
參數
解釋
function_name
必需。為待檢查的函式名稱。

例子

<?php
if (function_exists('phpinfo')) {
echo "phpinfo()函式已經定義.<br />";
} else {
echo "phpinfo()函式沒有定義.<br />";
}
?>
輸出結果為:
phpinfo()函式已經定義

實例

//判斷gif函式是否存在
if(function_exists("imagegif"))
{
//如果存在,以gif格式輸出
header("content-type: image/gif");
imagegif($im);
}
//判斷jpeg函式是否存在
elseif(function_exists("imagejpeg"))
{
//如果存在,以jpg格式輸出
header("content-type: image/jpeg");
imagejpeg($im, "", 0.5);
}
//判斷png函式是否存在
elseif (function_exists("imagepng"))
{
//如果存在,以png格式輸出
header("content-type: image/png");
imagepng($im);
}
//判斷wbmp函式是否存在
elseif (function_exists("imagewbmp"))
{
//如果存在,以bmp格式輸出

相關詞條

熱門詞條

聯絡我們