End of line-new line

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sheldon Glickler

    End of line-new line

    I have what I thought was a simple task. I have a file with an orderd list
    in it that I use in a readfile to generate an html page. When I want to
    insert a new entry into that list, it should be in the proper place. My
    procedure is to create an array using file('filename' ). I then search in
    that list for the proper placement, writing each line to a target file with
    an fwrite command. I write the new line and then I write the rest of the
    array. Simple, yes?

    Well, all the lines that I generated with the file command write back
    perfectly. I cannot seem to get the new entry to generate a line
    feed-carriage return. This is on a Windows system. I have tried "\n" and
    have "\r\n" and even nothing at all. No success. I have temporarily done a
    work-around by having the first line of the original file be blank and
    appending $lines[0] to the new entry where $lines is the array I generated.

    Any ideas? I would like to solve this the correct way.

    Note: I added the formatting as follows
    fwrite($handle, "The new entry information\r\n ");

    Shelly


  • Erwin Moller

    #2
    Re: End of line-new line

    Sheldon Glickler wrote:
    [color=blue]
    > I have what I thought was a simple task. I have a file with an orderd
    > list
    > in it that I use in a readfile to generate an html page. When I want to
    > insert a new entry into that list, it should be in the proper place. My
    > procedure is to create an array using file('filename' ). I then search in
    > that list for the proper placement, writing each line to a target file
    > with
    > an fwrite command. I write the new line and then I write the rest of the
    > array. Simple, yes?
    >
    > Well, all the lines that I generated with the file command write back
    > perfectly. I cannot seem to get the new entry to generate a line
    > feed-carriage return. This is on a Windows system. I have tried "\n" and
    > have "\r\n" and even nothing at all. No success. I have temporarily done
    > a work-around by having the first line of the original file be blank and
    > appending $lines[0] to the new entry where $lines is the array I
    > generated.
    >
    > Any ideas? I would like to solve this the correct way.
    >
    > Note: I added the formatting as follows
    > fwrite($handle, "The new entry information\r\n ");
    >
    > Shelly[/color]

    show some code please.

    Regards,
    Erwin Moller

    Comment

    • Sheldon Glickler

      #3
      Re: End of line-new line


      "Erwin Moller"
      <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
      message news:43fc31e5$0 $11065$e4fe514c @news.xs4all.nl ...
      [color=blue]
      > show some code please.[/color]
      The solution was to double quote the \n and \r. IOW have

      $to_be_written= $the_added_line . "\\r\\n" ;
      fwrite($handle_ for_open_file, $to_be_written) ;l.

      I found this buried dedep inside the fwrite documentation. I know, Iknow.
      RTFM.

      www.php.net is great.

      Shelly


      Comment

      Working...