![]() |
Presenting source code within html
For a school project a teacher asked me to make a php tutorial website. I want to be able to display php code within the html of the page. I also want to automatically add line numbers to the displayed code and? Is there an easy solution to this?
Thanks in advance |
You could have each line as an item in an ordered list and use CSS to display line numbers. There may be a better way to do this, but that's all I can think of.
|
I wouldn't mind doing it using an ordered list, but I really want to avoid doing it by hand if you know what I mean.
|
You could have a PHP script generate the output, although I agree that this solution is less than ideal. Hopefully someone will suggest a better solution.
|
here's a small script I wrote up to help you achieve what you want to achieve, AND it's in PHP ^_^
:
<pre> |
Wow, thanks a million!
|
You want to consider what will happen when the user copies and pastes the text on your site. Using both my method and grimpirate's, the line numbers will be included, which will be a great nuisance to users. I suggest providing a "download source" link for each code snippet on your site, or finding a better way to add line numbers.
|
Yes I have considered that, and I will provide a link where the users can view the plain code.
Again thanks for help!:) |
I haven't thought it through, myself, but since <pre> text doesn't add line-wrapping not in the original, have you considered making the line numbers part of the container? Even if a logical line wraps, you could accomodate it with a blank in the line number column.
|
I'm not entirely sure I understand what you're saying DaWei, I posted the script here at the PHP forum if you could explain a bit further. I just kinda threw this together to help out Wiz, but I'm willing to try and make it better if I can understand what you're getting at. Possibly like structuring it in a table?
|
| All times are GMT -5. The time now is 5:17 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC