在 PHP 中使用 \t 读取和打印

Read and print with \t in PHP

我正在 PHP 打开一个 TXT 文件,想逐行阅读它。

我正在使用 fgets() .

问题是输出忽略了原始文件中的制表符 ("\t"),这不是我想要的。

有一些方法强制PHP不要忽略他们?

我的代码:

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

您的(可能每个人都这样)网络浏览器忽略了标签。

试试这个:

$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>';