2016-07-19 34 views
0

我在PHP中打開了一個TXT文件,並且想要逐一讀取它的行。我正在使用fgets()閱讀並使用 t在PHP中打印

問題是輸出忽略了原始文件中的表格(「\ t」),這不是我想要的。

有一些方法強制PHP不要忽略'em

我的代碼:

$file = fopen("file.txt", "r") or die("<br><br>Error."); 
while (!feof($file)) { 
    $string = fgets($file, 4096); 
    echo "<br> " . $string; 
} 
+0

使用像'preg_replace'或'str_replace'打開'\ t'到的東西,更重要的是對你有用,如(4空格) – Martin

+2

php不會更改或忽略數據。問題一定在其他地方。 – Evert

+2

PHP是**不**忽略任何東西,您的網絡瀏覽器是。按'Ctrl + u'查看源代碼。 – MonkeyZeus

回答

1

你(也許每個人對於這個問題)的網頁瀏覽器是忽略的標籤。

試試這個:

$file = fopen("file.txt", "r") or die("<br><br>Error."); 
echo '<pre>' 
while (!feof($file)) { 
    $string = fgets($file, 4096); 
    echo "\n" . htmlentities($string); 
} 
echo '</pre>'; 

$file = fopen("file.txt", "r") or die("<br><br>Error."); 
echo '<textarea>' 
while (!feof($file)) { 
    $string = fgets($file, 4096); 
    echo "\n" . htmlentities($string); 
} 
echo '</textarea>'; 
+0

就是這樣。謝謝。 – Luiz