473,320 Members | 1,961 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.

highlight_file() strange line breaks

Hi,
Taking a closer look to highlight_file() lastly, I found out that its line
break policy was a bit.. strange.

<?php # highlight_file() line breaks test
$f = fopen('highlight_file_test', 'w');
fwrite($f, highlight_file(__FILE__, true));
fclose($f);
?>
highlight_test (00 -0F):
3C 63 6F 64 65 3E 3C 73 70 61 6E 20 73 74 79 6C <code><span styl
65 3D 22 63 6F 6C 6F 72 3A 20 23 30 30 30 30 30 e="color: #00000
30 22 3E>0A<3C 73 70 61 6E 20 73 74 79 6C 65 3D 0"<span style=

Here, the line break is obviously a LF (Line Feed, or \n).

highlight_test (A0 -AF):
26 6E 62 73 70 3B 74 65 73 74>0D<3C 62 72 20 2F &nbsp;test <br /

Here, it's a CR (Carriage Return, or \r).

All other line breaks are just CRs, except the two last ones (before the
last </spanand the </codetags), which are LFs like the first one.

As far as I know, only MacOS uses just CR for line breaks, as only Linux
does with LF (and Windows uses both of them, CR then LF). So.. what?

Firefox seems to render the source correctly (in its source window), and of
course, as it's XHTML formatted with <br /tags for line breaks, the final
render is fine. I know it's intended to be displayed in a browser and thus
there's no real problem with it, but I was just wondering (like, for
'educational' purpose ^^').. is that really a mess of things or is there an
actual reason for this?
Well, anyway, I think it's good to know for those who like a nice looking
rendered script source and for that are wishing to indent their php sources
highlights ;).

Thanks for your interest !

-thib´
Jan 13 '08 #1
1 1919
Rik Wasmus wrote:
That's not what I meant, I mean: the file that PHP actually is parsing
to generate it's output, are you sure that isn't the cause of this mess?
Oh, okay; well..
...I think you got it.

I configured my editor for it to put CR and LF as line break; I now updated
the file with just LFs and I got exactly four lines:
<code>
<span.. (source..)
</span>
</code>

=P.
So, I guess PHP removes all LFs but not CRs, then put the resulting source
between <code>\n<span.. and \n</span>\n</code>

Of course it's still kinda messed up, but there's less weirdness in all of
it. Thanks for your help finding this out ;).

-thib´
Jan 13 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: dan glenn | last post by:
Hi. I'm finding that if I have text entered into a <textarea ...> </textarea> in a form, and that text has leading blank lines (with no spaces or anything else), that when I retrieve the entered...
1
by: Bill | last post by:
I am downloading data from a website that displays it in a table $fp = fopen("a website page", 'r'); The following accesses the stream one <td> element at a time $myData = fgets($fp); Then I...
4
by: Luc | last post by:
Hello All, It's the first time I read the following code. A few js files like the one below, but I don't know how to make them readable by a human ( me ). Is it a strange character set ? an...
4
by: intl04 | last post by:
I have a memo field that is included in some Access reports I created. Is there some way for the memo field to display nicely formatted text, with line breaks between paragraphs? Or is it necessary...
2
by: Mike | last post by:
I need my textbox to work more smoothly with respect to line breaks. When I have data pulled from the database into a textbox there are hard line breaks at the end of each line (by definition how...
4
by: William Sullivan | last post by:
I have an extremely weird problem that I have no idea how to approach. I have a simple page with a search textbox and a search button. The button causes a postback, where I perform the search and...
5
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the...
2
by: caspardh | last post by:
i was trying to code a morse code decipherer which workd fine except that the .txt file that i was converting had linebreaks built in, i cant get python to ignore the line breaks and i cant find any...
3
by: Shisou | last post by:
Hey bytes community! this one is a really strange issue I ran into and I'm hoping you all can shine some light on it for me. This is written in C, not C++ I'm working on a program that reads...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.