showing syntax highlighted source

Problem

Want to display PHP code with syntax highlighting (colors). This helps with debugging, etc.



Solution

Within PHP you can nicely display colorful text, which can be very useful for debugging or just to showcase your code.

We simply use the highlight_file function within PHP, like this below.



Example


<?php highlight_file("transform.php"); ?>

For a real-life demo, take a look here:



Reference

[tags]PHP Syntax Highlighting, PHP Coding School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *