highlight_file() strange line breaks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?thib=B4?=

    #1

    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('highligh t_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´
  • =?UTF-8?B?dGhpYsK0?=

    #2
    Re: highlight_file( ) strange line breaks

    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´

    Comment

    Working...