Colour Coding PHP Output with HTML

Page last updated on 2011 / 04 / 09

All PHP scripts listed on this site use PHP's native "output HTML syntax highlighted source" function that can be used from the command line in this fashion.

php -s path_to_php_script.php > output_file.txt

Here is an example:

<?php

/*
This is a comment
*/
error_reporting(E_ALL);
ini_set("display_errors"1);

function 
test_function()
{
echo 
123;
echo 
"This is a test\n";
}

// This is another comment

?>

GeSHi

Another option is to use the comprehensive syntax highlighter GeSHi, which can color-code a number of languages and markup as well as PHP, including MySQL and bash for example. The following is the same code run through the GeSHi highlighter:

  1. <?php
  2. /*
  3. This is a comment
  4. */
  5. error_reporting(E_ALL);
  6. ini_set("display_errors", 1);
  7. function test_function()
  8. {
  9. echo 123;
  10. echo "This is a test\n";
  11. }
  12. // This is another comment
  13. ?>
  14.  

Previous Article
Parsing HTML with PHP
Next Article
How to Create Website Thumbnails with PHP





Tweet