<?php
  /**
   * Highlight a file.
   *
   * Provides better syntax highlighting, line numbering and function linking.
   *
   * @author      Aidan Lister <aidan@php.net>
   * @version     1.1.0
   * @link        http://aidanlister.com/repos/v/function.highlight_fiei.php
   * @param       string  $data       The string to add line numbers to
   * @param       bool    $return     return or echo the data
   * @param       bool    $linenum    Add line numbers or not
   * @param       bool    $funclink   Automatically link functions to the manual
   */

function hl($file) 
{
	echo "<hr/><h1>Code</h1>";
	highlight_filei($file);
}

function highlight_filei($file, $return = false, $linenum = true, $funclink = true)
{
	// Init
	$data = explode('<br />', highlight_file($file,true));
	$start = '<span style="color: black;">';
	$end   = '</span>';
	$i = 1;
	$text = '';
 
	// Loop
	foreach ($data as $line) {
        	$text .= $start . $i . ' ' . $end .
		str_replace("\n", '', $line) . "<br />\n";
        	++$i;
	}
	
	$text = str_replace('pouet2', 'password', $text);
 
	// Optional function linking
	if ($funclink === true) {
		$keyword_col = ini_get('highlight.keyword');
		$manual = 'http://fr.php.net/function.';
 
		if (version_compare('5.0.0', PHP_VERSION) === -1) {
			$text = preg_replace(
				// Match a highlighted keyword
                '~([\w_]+)(\s*</span>)'.
                // Followed by a bracket
                '(\s*<span\s+style="color: ' . $keyword_col . '">\s*\()~m',
                // Replace with a link to the manual
                '<a href="' . $manual . '$1">$1</a>$2$3', $text);
		} else {
			$text = preg_replace(
				// Match a highlighted keyword
                '~([\w_]+)(\s*</font>)'.
                // Followed by a bracket
                '(\s*<font\s+color="' . $keyword_col . '">\s*\()~m',
                // Replace with a link to the manual
                '<a href="' . $manual . '$1">$1</a>$2$3', $text);
		}
	}
    
	// Return mode
	if ($return === false) {
		echo $text;
	} else {
		return $text;
	}
}
 
?>