...

View Full Version : func.displayCode.php



Phil Jackson
10-22-2009, 05:35 AM
<?php

//http://www.actwebdesigns.co.uk
//luke@actwebdesigns.co.uk
//
//<style type="text/css">
//pre.odd { background-color: #F4F4F4; }
//pre.even { background-color: #a0d3a5; }
//pre.even, pre.odd { margin:0; padding:5px; font-size:12px; color:#404040; border-top:1px solid #404040;}
//div.codeBlock { width:800px; overflow:auto; margin:0 auto; border:1px solid #404040; border-top:none;}
//pre span.lineNo { color:#C60; }
//</style>

function displayCode($url)
{
if(file_exists($url))
{
$data = file_get_contents($url);
$lines = explode(PHP_EOL, $data);
$x=1;
$y=1;
$return = "<div class=\"codeBlock\">\n";
foreach($lines as $line)
{
if($x!==1)
{
$lineTest = trim($line);
if(!empty($lineTest))
{
$line = str_replace("&", "&amp;", $line);
$line = str_replace("/", "&#0047;", $line);
$line = str_replace("<", "&lt;", $line);
$line = str_replace(">", "&gt;", $line);
if(($x & 1)==1)
$class = "even";
else
$class = "odd";
if(preg_match("#(^\s*&\#0047;&\#0047)|(^\s*\#)#is", $line, $match))
{
$return .= "<pre class=\"".$class." comment\"><span class=\"lineNo\">".$y."</span> ".str_replace("/", "&#0047;", $line)."</pre>\n";
}
else
{
$return .= "<pre class=\"".$class."\"><span class=\"lineNo\">".$y."</span> ".str_replace("/", "&#0047;", $line)."</pre>\n";
}
$y++;
}
else
{
$x++;
}
}
$x++;
}
$return .= "</div>\n";
$return = preg_replace("#(\s*)@?([a-z]+(?:[a-z]|[0-9]|_)*)(\s*)\(([^\)]*)\)#is", "\\1<span class=\"function\">\\2\\3</span>(\\4)", $return);
$return = preg_replace("#\s*(\$[^\s]*)#is", " <span class=\"variable\">\\1</span>", $return);
return $return;

}
else
{
return "unknown path given";
}
}

//echo displayCode("../dir/to/page.php");
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum