I am converting an array to a text file. I'd like a
newline at the end of each array value, but have
thus far been too stupid to get one...

i.e., using 'implode' I can get:

1-2-3-4-5-6-7- etc.

 but not:

1
2
3
4
5
6
7

This seems reasonable, as \n would signify the end of
the string (right?). However, there has to be a way....so far,
weeding cursorily through the manual has yielded nothing...
I intend to continue, but would like the easy way out, as so many of us do...

...anyone care to share their experience?

Dalecosp

    is this linux or windows?

      Originally posted by PyroX

      is this linux or windows?

      Neither, but, of course '\n' would signify a standard UNIX newline, and such is the case.

      instead of '-' try '\n'

      I did, which is what occasioned this post. The use of the newline character in 'implode' truncates the string....

      for ($n=1; $n<=$MaxDays; $n++) {
              echo "Day #$n: &nbsp;&nbsp; $QuoteDay[$n]<br><br>\n";
              $QuoteFile="$QuoteFile" . "---" . "$QuoteDay[$n]";
      }
      
      $GetQuotes=explode("---", $QuoteFile);
      $AllQuotes=implode("\n", $GetQuotes);

      $AllQuotes is now equal to the first quote of the array only.

      Thanks for the suggestion, but methinks I'm ahead of you on that one, so far...any other ideas?

      dalecosp

        Originally posted by dalecosp
        I did, which is what occasioned this post. The use of the newline character in 'implode' truncates the string....

        Er, no it' doesn't ... how are you trying to display/write $AllQuotes?

          Originally posted by Weedpacket
          Er, no it' doesn't ... how are you trying to display/write $AllQuotes?

          The pertinent line, further down the page:

          fwrite ($FilePointer, "$AllQuotes");

          However, the reason I boldly (& perhaps erroneously) asserted that the string was truncated was because I inserted:

          echo "AllQuotes is $AllQuotes<br><br>";

          and I get "1---2---3---4---etc. using "---" as glue, while I get
          "1" using "\n".....

          😕
          Dalecosp

            Well, Weedpacket, it's a good thing I trust you! 🙂

            Since you said it wasn't so, I kept trying...when I tried
            ereg_replace and got similar results, I decided to check elsewhere...

            I must apologize to PyroX as well, I suppose....Seems the data is being corrupted by a badly coded HTML form tag.

            echo "<input type=hidden name=\"AllQuotes\"  value=$AllQuotes>

            $AllQuotes needed quotes.......

            Sorry, thx for your time....

            dalecosp

              Try...

              $AllQuotes = implode("<br>\n",$GetQuotes);

                Write a Reply...