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.


    value0
    value1
    value2
    valueN


    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


    thanks

  • 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.



    -Mike

  • 18 years ago

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

  • 18 years ago

    Got this from www.php.net:


    (http://www.php.net/manual/en/function.file.php)


    "Here is a quick snippet that will read in N number of lines of a file, then print them.
    $n=10
    $fp = file(/path/to/your/file);
    $i=0
    while($i < $n){
              echo "$fp[$i]";
               $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:


    chr(13).chr(10)


    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.


    zing

  • 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).

Contribute

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.

“Never trust a programmer in a suit.” - Anonymous