Forum Moderators: coopster

Message Too Old, No Replies

From "StrPos" to "Line Number and Column"

How to convert?

         

thing3b

4:24 am on Feb 8, 2008 (gmt 0)

10+ Year Member



In memory I have a long multi line string. I am currently using strpos to find the position of an item in this string, but would like to convert this to the line number the item is on and the column (position) on that line. How can I do this?

I though about counting the number of line breaks there are, but I am unsure if the line breaks will be \r, \n or \r\n.
Speed is an issue.

Does anyone have any ideas?

Cheers.

menace_sa

6:16 am on Feb 8, 2008 (gmt 0)

10+ Year Member



One way will be to change the newline to a <br> and then count the breaks?

$string = nl2br($string);

This will find all the newline data and replace it with a <br>