Skip to content

Instantly share code, notes, and snippets.

@luelista
Created February 28, 2013 16:22
Show Gist options
  • Select an option

  • Save luelista/5057930 to your computer and use it in GitHub Desktop.

Select an option

Save luelista/5057930 to your computer and use it in GitHub Desktop.
Pretty Printer for PHP source code
<?php
// Pretty Printer for PHP source code
// Edit the (relative or absolute) path to your project here:
$root = "../../Notendb/notendb2/";
// Edit the page title here:
$pageTitle = "Notendb - Anhang B: Quelltext";
?><html><head>
<meta charset="utf8">
<style>
@page {
size: auto;
margin: 15mm 8mm 10mm 20mm;
}
@page :left {
margin-left: 5mm;
margin-right: 25mm;
}
@page :right {
margin-left: 25mm;
margin-right: 5mm;
}
th { border:2px solid #ddd; text-align:center; }
code { white-space:pre-wrap; }
html,body,td { margin: 0; padding: 0; font-size: 8.5pt; }
table {width:100%}
table,thead,tbody,tr { margin: 0; padding: 0; }
</style>
<title><?= $pageTitle ?></title>
</head><body>
<?php
$files=array();
function add_files($dir,$sd,$ext) {
global $files;
$dh=opendir($dir.$sd); $el=-strlen($ext);
while($f=readdir($dh)) {
if($f=="."||$f=="..")continue;
if(is_dir($dir.$sd.$f)) add_files($dir, $sd.$f.'/', $ext);
elseif (strtolower(substr($f,$el))==$ext) $files[]=$sd.$f;
}
closedir($dh);
}
add_files($root,"",".php");
add_files($root,"",".htaccess");
add_files($root,"",".sql");
sort($files);
$pb=false;
$max=count($files);
if (isset($_GET['max'])) $max=$_GET['max'];
for($i=0; $i<$max; $i++) {
$f = $files[$i];
echo "<table style='".($pb?"page-break-before:always":"")."'><thead><tr><th bgcolor='#eeeeee'><b>".$f."</b></th></tr></thead>
<tbody><tr><td>";
echo str_replace("&nbsp;"," ",highlight_string(str_replace("\r","",file_get_contents("$root$f")),true));
echo "</td></tr></tbody></table>\n\n\n\n";
$pb=true;
}
?>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment