![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Professional Programmer
|
DaWei is suggesting that the line numbers and the actual code should be split into two columns so you could select only the code column and avoid the line numbers. I think...
__________________
JG-Webdesign |
|
|
|
|
|
#12 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Note that the images are deliberately degraded to reduce bandwidth demands on the forum.
![]() ![]()
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#13 |
|
King of Portal
|
I got ya now DaWei and here is the source that does what you're asking for[PHP]<html>
<head> <title>Grim PHP Syntax Highlighter</title> <style> div.lineNumbers { float: left; text-align: left; border-right: 1px #999999 solid; margin-right: 8px; } </style> </head> <body> <span style="font-family: Courier New; font-size: 10pt"> <?php $filename = 'syntax_h.php'; ob_start(); highlight_file($filename); $source = ob_get_contents(); ob_end_clean(); $source = explode(chr(13), $source); $temp = substr($source[0], 0, 35); $temp .= substr($source[0], 36); $source[0] = substr($temp, 6); $temp = substr($source[count($source) - 1], 0, strlen($source[count($source) - 1]) - 8); $source[count($source) - 1] = $temp; for($i = 1; $i < count($source); $i++){ $source[$i] = substr($source[$i], 6); } for($i = 0; $i < count($source) - 1; $i++){ $source[$i] .= '<br />'; } $lineNum = array(); $spaces = strlen(count($source)); for($i = 0; $i < count($source); $i++){ array_push($lineNum, '<span style="color: #777777">' . ($i + 1) . '</span> '); for($j = 0; $j < $spaces - strlen($i + 1); $j++){ $lineNum[$i] = ' ' . $lineNum[$i]; } $lineNum[$i] .= '<br />'; } echo '<div class="lineNumbers">'; for($i = 0; $i < count($lineNum); $i++){ echo $lineNum[$i]; } echo '</div>'; echo '<div class="sourceCode">'; for($i = 0; $i < count($source); $i++){ echo $source[$i]; } echo '</div>'; ?> </span> </body> </html>[/PHP]Or at least it does it on my computer hehe ^_^. Only tested it on Mozilla FireFox and Internet Explorer though.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#14 |
|
Professional Programmer
|
Yeah this is a really usefull piece of code.
![]()
__________________
JG-Webdesign |
|
|
|
|
|
#15 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
Quote:
php Syntax (Toggle Plain Text)
css Syntax (Toggle Plain Text)
|
|
|
|
|
|
|
#16 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Exploding on a string such as "<br /"> may not be effective. Many textual source code files never heard of "<br /"> or its variants, such as "<br/>". The idea is to reproduce logical lines in such a way that the resulting code is usable as reproduced, when copied intact. Since languages vary in this respect, it means reproducing the text in a way that will be acceptable to the target interpretation.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#17 |
|
Expert Programmer
|
Here is a shorter version of Arevos' code. It solves the issue of exploding on "<br />" brought up by DaWei.
PHP Syntax (Toggle Plain Text)
|
|
|
|
|
|
#18 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4
![]() |
I'm don't quite get why "<br />"s would be a problem, assuming the functionality of highlight_file remains the same.
Titaniumdecoy's code is a lot neater, however. I'm rather jealous I didn't think of doing it that way, myself ![]() |
|
|
|
|
|
#19 |
|
Programmer
Join Date: Mar 2007
Posts: 39
Rep Power: 0
![]() |
That is interesting =D
so finally, it can be shortened to: [php]<?php $file = 'test.php'; echo '<code class="num">', implode(range(1, count(file($file))), '<br />'), '</code>'; highlight_file($file); ?>[/php] css Syntax (Toggle Plain Text)
|
|
|
|
|
|
#20 |
|
Expert Programmer
|
Did you test that code, Styx? It doesn't work in my browser, as the code is shifted below the line numbers.
Last edited by titaniumdecoy; Mar 20th, 2007 at 8:38 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| start Learning HTMl | smita | HTML / XHTML / CSS | 0 | Mar 15th, 2007 7:38 AM |
| GCC sprintf Source Code | JawaKing00 | C | 2 | Nov 30th, 2006 3:53 AM |
| Basic HTML Tutorial - Reuben Keeney | ReubenK | HTML / XHTML / CSS | 14 | Mar 26th, 2006 5:50 AM |
| Image processing:Stentiford and Holt Thinning Source code in C or C++ | ladyscarlet99 | C | 0 | Sep 9th, 2005 1:20 AM |