PHP: Testing for Function Existence

Start PHP Code RESULT
make me bold

underline me too

"make me italic and quote me"
End PHP Code RESULT

 

The PHP Code START
<?php
function tagwrap( $tag, $txt, $func="") {
    if ( ! empty( $txt) && function_exists($func))
        $txt = $func($txt);
    return "<$tag>$txt</$tag>\n";
}
function underline( $txt ) {
    return "<u>$txt</u>\n";
}

print tagwrap('b', 'make me bold');
print "<br /><br />";
print tagwrap('i', 'underline me too',"underline");
print "<br /><br />";
print tagwrap('i', 'make me italic and quote me',create_function('$txt','return ""$txt"";'));
?>
The PHP Code END

Back to Bill's PHP