note 83820 deleted from function.highlight-string by felipe

From: Date: Sun, 15 Jun 2008 11:41:27 +0000
Subject: note 83820 deleted from function.highlight-string by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140458@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- Here is an improved version of the code highlighter w/ linenumbers from 'vanessaschissato at gmail dot com' - http://nl.php.net/manual/en/function.highlight-string.php#70456 <?php function printCode($source_code) { if (is_array($source_code)) return false; $source_code = explode("\n", str_replace(array("\r\n", "\r"), "\n", $source_code)); $line_count = 1; foreach ($source_code as $code_line) { $formatted_code .= '<tr><td>'.$line_count.'</td>'; $line_count++; if (ereg('<\?(php)?[^[:graph:]]', $code_line)) $formatted_code .= '<td>'. str_replace(array('<code>', '</code>'), '', highlight_string($code_line, true)).'</td></tr>'; else $formatted_code .= '<td>'.ereg_replace('(&lt;\?php&nbsp;)+', '', str_replace(array('<code>', '</code>'), '', highlight_string('<?php '.$code_line, true))).'</td></tr>'; } return '<table style="font: 1em Consolas, \'andale mono\', \'monotype.com\', \'lucida console\', monospace;">'.$formatted_code.'</table>'; } ?>

« previous php.notes (#140458) next »