line breaks when reading a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Glaeser

    #1

    line breaks when reading a file

    Consider the code:

    $arrText = file ("http://www.site.com/page.htm");
    for ($i=0; $i<count($arrTe xt); i++) {
    echo("$arrText[$i]\n");
    }

    (I did not test the snippet for errors)

    The line breaks appear to be different from the original .htm file. Why?

    Best,
    Christopher


  • John Dunlop

    #2
    Re: line breaks when reading a file

    Christopher Glaeser wrote:
    [color=blue]
    > $arrText = file ("http://www.site.com/page.htm");
    > for ($i=0; $i<count($arrTe xt); i++) {
    > echo("$arrText[$i]\n");
    > }
    >
    > (I did not test the snippet for errors)
    >
    > The line breaks appear to be different from the original .htm file.[/color]

    You're adding a linefeed character to each line of the original
    source. Newlines aren't stripped by file; to remove them, the Manual
    suggests rtrim. (It actually says you "*need* [emphasis added] to use
    rtrim()".)



    --
    Jock

    Comment

    Working...