473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

numbered code lines

32
I really like the numbered code lines on this forum. I would like to incorporate something like this on my own site, and was wondering how exactly it was done? I am assuming that its creating some type of loop, delimiting by newline character, and inserting the n+1 where n is the number last new line character integer.
Sep 14 '07 #1
5 1486
Atli
5,058 Expert 4TB
Hi.

You could set up a loop, searching for \n characters using the strpos() function, which would give you their position. Meanwhile, you could use the substr_replace() function, inside the loop, to replace each of the new-line characters with an integer that is incremented each time.

If that's complete gibberish, please let me know and I'll try to rephrase.
Sep 14 '07 #2
pbmods
5,821 Expert 4TB
Heya, JGentes.

Actually, TheScripts uses an ordered list.
Sep 14 '07 #3
Atli
5,058 Expert 4TB
Heya, JGentes.

Actually, TheScripts uses an ordered list.
That's way to simple!... I'd never have though of that :D
Sep 14 '07 #4
jgentes
32
so you explode them to an array by some newline delimiter? then implode them using an ordered list?
Sep 17 '07 #5
Atli
5,058 Expert 4TB
I would assume so yes.

Somewhat like this:
Expand|Select|Wrap|Line Numbers
  1. <ol>
  2. <?php
  3.     $arr = explode("\n", $yourCode);
  4.     foreach($arr as $line) {
  5.         echo "<li>$line</li>";
  6.     }
  7. ?>
  8. </ol>
  9.  
Sep 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: John Burton | last post by:
I wrote a python program on windows which needs to listen for connections on a low numbered port which works fine on windows but on linux you need to be *root* in order to listen for connections on...
3
by: Jeff Thies | last post by:
I have search results coming back and they need to be numbered. Sounds like an ordered list... It needs to look like this: 1. ********** line one of information * image* line...
2
by: Chris | last post by:
I have a script that will navigate back and foreward using a form. The files it navigates are named: bg1.html, bg2.html, bg3.html, etc. This is happening in a frameset, where my BACK and FORWARD...
3
by: RR | last post by:
We have cards that are numbered consecutively. These cards are given out to different people in different sized batches. One group might get 5, the next group might get 20. What is a good...
1
by: Andrea Moro | last post by:
As object, I need to implement in a memo or textbox multiline a structured numbered list. I've written some code, that is working, but I'm finding a lot of problems when I need to add elements...
24
by: rudranee | last post by:
hi there, can anyone tell me how to lines from a file which are odd numbered i.e. 1st,3rd,5th...lines. i tried incrementing file pointer by 2 (fp=fp+2) but it does'nt work Can someone give me...
9
by: joba | last post by:
Hi, I am building a program to calculate vacations for employees. Can anyone show me how to write a VBA code to differentiate even-numbered (Eg 2005) years from odd - numbered(Eg.2006) years. ...
0
by: said76 | last post by:
Hi, I have a question in regards to Word VBA. In word document, there is bullet and numbering feature where you can customise the numbering. My question is whether there is a way that i can get...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.