PHP/Functions/function exists

Материал из Web эксперт
Перейти к: навигация, поиск

bool function_exists ( string function_name ) returns true if that function is available for use.

 
<?
    if (function_exists("imagepng")) {
            echo "You have the GD extension loaded.";
    } else {
            echo "Can"t find imagepng( ) - do you have GD loaded?";
    }
?>



Testing for a Function"s Existence

 
<html>
<body>
<div>
<?php
    function tagWrap( $tag, $txt, $func="" ) {
      if ( function_exists( $func ) )
        $txt = $func( $txt );
      return "<$tag>$txt</$tag>\n";
    }
    
    function subscript( $txt ) {
      return "<sub>$txt</sub>";
    }
    
    print tagWrap("b", "bold");
    
    print tagWrap("i", "i", "subscript");
   
?>
</div>
</body>
</html>