Syntax highlighted code
Have you ever wanted to display your PHP code examples but wanted to display them syntax highlighted . The colors are defined with the built in syntax highlighter in php . Lets look at the code and then see an example .
Code :
<?php
function sourcecode($url)
{
//clear file stat cache
clearstatcache();
//if the file doesnt exist
if(!file_exists($url))
{
return 1;
}
//open the url
$fp=fopen($url,"r");
//get the size of the url
$size=filesize($url);
//store in the temp variable
$temp=fread($fp,$size);
//display color coded syntax highlighting
$coloredcode=highlight_string($temp);
return 0;
}
//call the function with a url
sourcecode("gdsample1.php");
?>
Example :