【问题标题】:Does PHP file_get_contents() automatically turn contents into ASCII?PHP file_get_contents() 是否会自动将内容转换为 ASCII?
【发布时间】: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


【解决方案1】:

它不会将内容转换为 ASCII。因为它只是获取文件的内容,所以不需要。 更多信息在http://us3.php.net/manual/en/function.file-get-contents.php

【讨论】:

  • 虽然链接很棒,但可以移动或删除资源。除了链接之外,最好在帖子中提供解释。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-28
  • 1970-01-01
  • 2012-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-16
相关资源
最近更新 更多