Home | Scripts | Tutorials | Books | Hosting | Forums | Links|

Navigation:

Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Blog
Books
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links






 
 

SPONSORS



 
 

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 :