Flukey Posted December 1, 2006 Share Posted December 1, 2006 Hey guys,This code was found on php.net/highlight_string under the comments section.Anyhows, there is a slight flaw with it, being that it can't parse multi-line comments as an error is thrown up.[code=php:0]// Function used to highlight code and print line numbersfunction printCode($code, $high_light, $lines_number) { if (!is_array($code)) $code = explode("\n", $code); $count_lines = count($code); foreach ($code as $line => $code_line) { if ($lines_number) $r1 = "<span class=\"lines_number\">".($line + 1)." </span>"; if ($high_light) { if (ereg("<\?(php)?[^[:graph:]]", $code_line)) { $r2 = highlight_string($code_line, 1)."<br />"; } else { $r2 = ereg_replace("(<\?php )+", "", highlight_string("<?php ".$code_line, 1))."<br />"; } } else { $r2 = (!$line) ? "<pre>" : ""; $r2 .= htmlentities($code_line); $r2 .= ($line == ($count_lines - 1)) ? "<br /></pre>" : ""; } echo "<table>"; $r .= "<tr><td>$r1</td><td>$r2</td></tr>"; } echo "<div class=\"code\">".$r."</div>"; }[/code]Any ideas how to modify that to accept multi-line comments?I understand how the function works, but i'm not sure how to modify to get it to do what I want.Cheers guys,Flukes :) Link to comment https://forums.phpfreaks.com/topic/29090-highlight-string-function/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.