66

prettyfile

pretty_file
SYNOPSIS

pretty_file($file, $language, $startline=0, $endline=0, $number=false)

DESCRIPTION
CODE
  1. require_once 'geshi.php';
  1.  
  2.     $s=read_file($file, $startline, $endline);
  3.  
  4.     if (!$s) {
  5.         return false;
  6.     }
  7.  
  8.     if (!$language) {
  9.         return $s;
  10.     }
  11.  
  12.     $output = false;
  13.  
  14.     switch ($language) {
  15.         case 'plain':
  16.             $s = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $s);
  17.             $s = htmlentities($s, ENT_COMPAT, 'UTF-8');
  18.  
  19.             $output = '<pre class="plain">' . PHP_EOL . $s . '</pre>' . PHP_EOL;
  20.             break;
  21.         default:
  22.             $geshi = new GeSHi($s, $language);
  23.             $geshi->enable_classes(true);
  24.             $geshi->set_header_type(GESHI_HEADER_DIV);
  25.             if ($number) {
  26.                 $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
  27.                 $geshi->start_line_numbers_at($startline > 0 ? $startline : 1);
  28.             }
  29.             $geshi->enable_keyword_links(false);
  30.             $geshi->set_tab_width(4);
  31.  
  32. //          echo '<pre>' . PHP_EOL .$geshi->get_stylesheet( ). '</pre>' . PHP_EOL;
  33.  
  34.             $output = $geshi->parse_code();
  35.  
  36.             if ($geshi->error()) {
  37.                 return false;
  38.             }
  39.     }
  40.  
  41.     return $output;
  42. }
read_file
SYNOPSIS

read_file($file, $startline=0, $endline=0)

DESCRIPTION
CODE
  1. function read_file($file, $startline=0, $endline=0) {
  2.     $lines = @file($file);
  3.  
  4.     if ($lines === false) {
  5.         return false;
  6.     }
  7.  
  8.     if ($startline or $endline) {
  9.         $offset=$startline ? $startline-1 : 0;
  10.  
  11.         if ($endline) {
  12.             $length=$startline ? $endline - $startline + 1 : $endline;
  13.             $lines = array_slice($lines, $offset, $length);
  14.         }
  15.         else {
  16.             $lines = array_slice($lines, $offset);
  17.         }
  18.     }
  19.  
  20.     $s=implode('', $lines);
  21.  
  22.     $s=rtrim($s);
  23.  
  24.     return $s;
  25. }
  26.  
  27. function pretty_file($file, $language, $startline=0, $endline=0, $number=false) {
  28.     if (!$file) {
  29.         return false;

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].