Created
November 14, 2012 02:42
-
-
Save jquast/4069965 to your computer and use it in GitHub Desktop.
ansi-codes.php ansi.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// -rwxr--r-- 0 jeremy users 1982 Feb 12 2003 ansi-codes.php | |
// -rwxr--r-- 0 jeremy users 1166 Feb 13 2003 ansi.php | |
function ansi_decode($ansicodes){ | |
$fontline="<font "; | |
$ansi=explode(";",$ansicodes[0]); | |
$attrib=0; | |
for($code=0;$code<count($ansi);$code++){ | |
switch ($ansi[$code]) { | |
case 0: | |
print "</font>"; | |
break; | |
case 1: | |
$attrib=1; | |
break; | |
case 30: | |
if($attrib==0){ | |
$fontline=$fontline."color=000000"; | |
}else{ | |
$fontline=$fontline."color=848484"; | |
} | |
break; | |
case 31: | |
if($attrib==0){ | |
$fontline=$fontline."color=cc0000"; | |
}else{ | |
$fontline=$fontline."color=ff0000"; | |
} | |
break; | |
case 32: | |
if($attrib==0){ | |
$fontline=$fontline."color=008800"; | |
}else{ | |
$fontline=$fontline."color=44ff44"; | |
} | |
break; | |
case 33: | |
if($attrib==0){ | |
$fontline=$fontline."color=000088"; | |
}else{ | |
$fontline=$fontline."color=ffff44"; | |
} | |
break; | |
case 34: | |
if($attrib==0){ | |
$fontline=$fontline."color=040284"; | |
}else{ | |
$fontline=$fontline."color=0402fc"; | |
} | |
break; | |
case 35: | |
if($attrib==0){ | |
$fontline=$fontline."color=840284"; | |
}else{ | |
$fontline=$fontline."color=fc02fc"; | |
} | |
break; | |
case 36: | |
if($attrib==0){ | |
$fontline=$fontline."color=ace2fc"; | |
}else{ | |
$fontline=$fontline."color=04fefc"; | |
} | |
break; | |
case 37: | |
if($attrib==0){ | |
$fontline=$fontline."color=9f9f9f"; | |
}else{ | |
$fontline=$fontline."color=ffffff"; | |
} | |
break; | |
} | |
} | |
$fontline=$fontline.">"; | |
echo $fontline; | |
} | |
?> | |
<?php | |
include("ansi-codes.php"); | |
print "<body bgcolor=000000>\n"; | |
print "<pre><TT><font color=FFFFFF>\n"; | |
if(!$file||!file_exists($file)){ | |
print "You may want to specify a file (or one that exists)\n"; | |
}elseif(strstr($file,"/")){ | |
print "Why you gotta do shit like that man?!\n"; | |
}else{ | |
$handle=fopen($file,r); | |
while (!feof($handle)){ | |
$buffer = fgets($handle, 4096); | |
$shrapnel=explode(chr(27)."[",$buffer); | |
if(strlen($buffer)!=strlen($shrapnel[0])){ | |
for($x=0;$x<count($shrapnel);$x++){ | |
$ansicodes=explode("m",$shrapnel[$x]); | |
if(strlen($ansicodes[0])&&count(explode(";",$ansicodes[0]))>2){ | |
ansi_decode($ansicodes); | |
for($y=strpos($shrapnel[$x],"m")+1;$y<strlen($shrapnel[$x]);$y++){ | |
print htmlspecialchars($shrapnel[$x][$y]); | |
} | |
}else{ | |
print htmlspecialchars($shrapnel[$x]); | |
} | |
} | |
}else{ | |
print htmlspecialchars($buffer); | |
} | |
print "\n"; | |
} | |
} | |
print "</TT></pre>\n"; | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment