2013-07-30 49 views
0

當我嘗試創建一個文件時,我無法換行/回車。 爲什麼它不起作用?我試着用:新行創建文件

  • PHP_EOL
  • \n

但是,當我用記事本看它,它也沒有創造新的生產線

<?php 

$file = 'myText.txt'; 

$id = '1'.$file; 
//explode($delimiter, $id); 

$content = "<PMTags1.0 win>". PHP_EOL; 
$content .= . PHP_EOL; 

while($row = mysqli_fetch_array($result)) 
{ 
    $content .= "<@win:><\<>win>". $row['kategoria'] . PHP_EOL; 
    $content .= "<@tekst:><\<>tekst><$>"; 
    $content .= $row['text']; 
    $content .= $gcid.$row['id'].'/'. PHP_EOL; 
} 

utf8_encode($content); 
echo $content; 
//Stworzenie pliku 
$fp = fopen(trim(trim($id)),"wb"); 

fwrite($fp,$content); 
fwrite($fp, pack("CCC",0xef,0xbb,0xbf)); 
fopen(trim(trim($id)),"r"); 
fclose($fp); 
//End 4 
//5 - Otwarcie pliku 



if (file_exists(trim($id))) { 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename='.basename(trim($id))); 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize(trim($id))); 
    ob_clean(); 
    flush(); 
    readfile(trim($id)); 
    exit; 
} 
+1

記事本不會向你顯示'\ n',這是一條看不見的指令。 – Prix

+5

嘗試記事本++。它好多了。 –

+2

如果您在使用* nix行結尾(「\ n」)的服務器上創建文件,但在Windows記事本中顯示需要窗口行尾的文件(「\ r \ n」),那麼它看起來好像是一行 - 無論是在Notepad ++中打開文件還是使用* nix行結尾讀取文件的編輯器,或者使用「\ r \ n」 –

回答

1

對於Linux系統的新行字符是\n

對於Mac系統\r就夠了(謝謝SIT_LCU)。

對於Windows接下來必須添加\r\n

+0

實際上,有些Mac系統只依賴於'\ r'。參考:http://en.wikipedia.org/wiki/Crlf#Representations –

0

PHP_EOL是「正確的‘高端路線’符號這個平臺。」

但是你可能在Unix上創建了這個文件並且在Windows下查看它---symbol是不同的。

+0

是serwer是在UNIX上,我打開窗口上的文件 – user33913

+0

正如其他人所建議的,一個好的編輯將會有所幫助。 [Notepad ++](http://notepad-plus-plus.org/)或[UltraEdit](http://www.ultraedit.com/)(我的最愛)將會是套房... – MBaas

1

簡單地說,

\r\n 

是您的解決方案。

1

不要使用PHP_EOL爲文本文件的輸出,可以更好的使用:

\n\r 

爲了更好的兼容性

0

\ N = CR(回車)//作爲一種新線字在Unix的
\ R = LF(換行)//用作在Mac的一個新行字符OS
\ r \ N = CR + LF //在Windows
用作一個新行字符 NewLine

\ n在某些瀏覽器和工具中正確表示,
但要獲得所有用戶的正確結果,最好對新行使用「\ r \ n」。