Tuesday, May 19, 2009

Using PHP's Built-in Source Highlighter

PHP offer two functions for highlighting PHP code: highlight_file() and highlight_string(). Both functions return the same results, but each has its own specific input parameters. As their names suggest, the first function takes the filename of the PHP script whose code is to be highlighted, while the second takes the input as a string.

A Quick Example

Let's take a look at an example of the highlight_string() function in action:

include_once 'init.inc.php';

if (!empty($_POST['text'])){

echo '

';
highlight_string($_POST['text']);
echo '
';
}
?>

" method="post">




No comments:

Post a Comment