highlight_file() strange line breaks
highlight_file() strange line breaks
am 13.01.2008 03:18:36 von thyb0
Hi,
Taking a closer look to highlight_file() lastly, I found out that its line
break policy was a bit.. strange.
$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
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">
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 test
Here, it's a CR (Carriage Return, or \r).
All other line breaks are just CRs, except the two last ones (before the
last and the
tags), 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
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´
Re: highlight_file() strange line breaks
am 13.01.2008 03:23:17 von luiheidsgoeroe
On Sun, 13 Jan 2008 03:18:36 +0100, thib´
wrote:
> Taking a closer look to highlight_file() lastly, I found out that its
> line break policy was a bit.. strange.
> Here, the line break is obviously a LF (Line Feed, or \n).
> Here, it's a CR (Carriage Return, or \r).
> Firefox seems to render the source correctly (in its source window), and
> of course, as it's XHTML formatted with
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?
Hmm, it would be very strange indeed, however, I don't think the function
has ever been regarded as very important by ayone :P. Just out of
curiousity: have you compared this to existing linebreaks in the document
highlighted itself?
--
Rik Wasmus
Re: highlight_file() strange line breaks
am 13.01.2008 03:33:51 von thyb0
> Hmm, it would be very strange indeed, however, I don't think the
> function has ever been regarded as very important by ayone :P. Just out
> of curiousity: have you compared this to existing linebreaks in the
> document highlighted itself?
Yes, Firefox doesn't replace the CRs with any LF or CR/LF, nor the LFs with
any CR/LFs.
Bug report, for principles? ^^'
I agree with you when you say that this func' has never been considered as
important, as every source sharing website should have its own parser, but I
thought it was worth pointing it out :).
-thib´
Re: highlight_file() strange line breaks
am 13.01.2008 03:44:58 von luiheidsgoeroe
On Sun, 13 Jan 2008 03:33:51 +0100, thib´
wrote:
>> Hmm, it would be very strange indeed, however, I don't think the
>> function has ever been regarded as very important by ayone :P. Just out
>> of curiousity: have you compared this to existing linebreaks in the
>> document highlighted itself?
>
> Yes, Firefox doesn't replace the CRs with any LF or CR/LF, nor the LFs
> with any CR/LFs.
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?
> Bug report, for principles? ^^'
Lets hold off just one second untill we're clear :)
--
Rik Wasmus
Re: highlight_file() strange line breaks
am 13.01.2008 07:09:46 von thyb0
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:
=P.
So, I guess PHP removes all LFs but not CRs, then put the resulting source
between \n\n
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´