Page 1 of 1

Weird php problem [SOLVED]

PostPosted: 10. September 2008 18:34
by in-sanity
Hi all,

I'm experiencing some dificulties writing some multi-line text using fwrite().

In short, when running the following code:

Code: Select all
$file = fopen(EXE_DIR.'\bon.txt', 'w');
      foreach ($info as $linie) {
         $line .= '1;'.substr(strtoupper($linie['nume_produs']), 0, 20).';1;1;1;'.$linie['pret_produs'].';'.($linie['cantitate_produs']*1000).';0\r\n';
      $line .= '3';
      fwrite($file,$line, strlen($line));

I get the following result:

Code: Select all
1;CARTELE DIGI;1;1;1;1;1000;0\r\n1;DISPOZITIV GRI-GRI P;1;1;1;1;1000;0\r\n1;MASă CU Tă;1;1;1;11;11000;0\r\n3

From what I can gather, php does not parse the \r\n special characters for inserting a carriage-return and new-line.

I also tried to use simple
Code: Select all
echo 'This\r\nis\r\na\r\ntext.\r\n';
the result being the same, the special characters are simply printed out as they are.

Any help is most appreciated.

Thank you, in-sanity.

PostPosted: 10. September 2008 21:45
by glitzi85