Picatta Posted March 26, 2006 Share Posted March 26, 2006 I started learning php not too long ago, and recently decided to start a project which would let me display the sourcecode of a file and display it with line numbers and syntax highlighting. Everything was going smooth and I had gotten line numbers to work, but I can't figure out syntax highlighting. The sourcecode so far is:[code]<?phpif (empty($_GET['method'])) {print "<html><head></head><body><form ENCTYPE=\"multipart/form-data\" action=?method=display method=POST>Source: <br /><input type=file name=source><br /><br /><input type=submit name=submit value=Display></form></body></html>";} elseif ($_GET['method'] == "display") {print "<html><head></head><body><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td align=center></td><td align=center><INPUT type=button value=BACK onClick=history.back()></td></tr><tr><td bgcolor=#000099 align=center><font color=#FFFFFF> # </font></td><td bgcolor=#000099 align=center><font color=#FFFFFF> Line </font></td></tr>";$spacer = " ";$fname = file($_FILES['source']['tmp_name']);$int = 2;foreach($fname as $line => $fline) { $fline = htmlspecialchars($fline); print " <tr> <td bgcolor=#000099 align=center><font color=#FFFFFF> [$line] </font></td> <td "; if ($int % 2 != 0) {$bgcolor = "CCCCCC";} else {$bgcolor = "BBBBBB";}; print "bgcolor=$bgcolor><code> $spacer$fline</code></td> </tr> "; $int++;}print "<tr><td bgcolor=#000099 height=20></td><td bgcolor=#000099 height=20></td></tr></table></body></html>";}?>[/code]I tried using highlight_string to highlight it, and then explode() it at the <br /> part, but since it was split into table cells it didn't work. A point in the right direction would be nice. Quote Link to comment https://forums.phpfreaks.com/topic/5876-source-code-display/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.