write a newline character to a text file

  • 18 years ago

    i've got a load of values in an array and i'm writing each of them to a text file. I want each one on a line of its own, eg.


    I'm currently using the newline character by appending "\n" to the array element.... but once i've run my script I open the text file in notepad and it's they're all on the same line separated by a newline character, but it doesnt display as a newline... it's a square and they're all on one line!!

    eg: value0?value2?value3?value4?value5?value6

    any ideas would be appreciated. i'll post my code if necessary


  • 18 years ago

    Have you tried adding \r to that?
    sometimes with somethings you need '\n\r' .

    Not that I know PHP or anything,
    it's just that that's been a
    problem for me too once or twice.


  • 18 years ago

    thanks for the idea... but that just puts two squares in instead!

  • 18 years ago

    Got this from www.php.net:


    "Here is a quick snippet that will read in N number of lines of a file, then print them.
    $fp = file(/path/to/your/file);
    while($i < $n){
              echo "$fp[$i]";
    I am using this right now to display the current progress of the seti@home client working on my server, instead of displaying the whole thing, which isn't web page friendly.
    Because sometimes short really is sweet..."

    or even:
    "You can always directly insert a carriage return and line feed:


    Seems to work fine for me. Remember to use them together as some text readers wont recognise these separately. e.g. chr(13) (carriage return) in some cases will display an invalid character at the point where you wanted a new line. Adding chr(10) solves this.
    I find it handy to make it a global var.

    I know it's small but hopefully this helps someone who has to develop script for a few different platforms. It helps me."

    Hope this helps - can't say I entirely understood it.


  • 18 years ago

    cheers mate, adding the characters explicitly worked a treat

    (didn't know u could do it like that in PHP as well as ASP! learn a new thing every day...)

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare