【发布时间】:2014-12-16 08:47:15
【问题描述】:
假设我想知道一个文本文件的编码, PHP file_get_contents 会自动将内容转成 ASCII 码吗?
<pre>
<?php
$file = file_get_contents('./test.txt', true);
echo $file."<br>".mb_detect_encoding($file);
echo "<br>";
$file = file_get_contents('./test (2).txt', true);
echo $file."<br>".mb_detect_encoding($file);
echo "<br>";
$file = file_get_contents('./test (3).txt', true);
echo $file."<br>".mb_detect_encoding($file);
?>
【问题讨论】:
-
不,PHP 不在乎 - 它没有必要。因此,无论如何编码的文本将是您正在使用的内容。或者它已经被修改为传输 - (读心模式)...你有没有机会在 ASCII 中使用 FTP 客户端而不是二进制模式?
-
@Emissary Heh... 我的旧项目都使用 ASCII 的众多原因之一——除此之外的任何内容在发送到服务器之前都被编码为 HTML 实体(并且任何非 ASCII 输入都是被拒绝)。啊,我是多么愚蠢地认为把问题扫到地毯下是个好主意!
标签: php text file-get-contents