1. <i id='qYqf5'><tr id='qYqf5'><dt id='qYqf5'><q id='qYqf5'><span id='qYqf5'><b id='qYqf5'><form id='qYqf5'><ins id='qYqf5'></ins><ul id='qYqf5'></ul><sub id='qYqf5'></sub></form><legend id='qYqf5'></legend><bdo id='qYqf5'><pre id='qYqf5'><center id='qYqf5'></center></pre></bdo></b><th id='qYqf5'></th></span></q></dt></tr></i><div id='qYqf5'><tfoot id='qYqf5'></tfoot><dl id='qYqf5'><fieldset id='qYqf5'></fieldset></dl></div>

    2. <small id='qYqf5'></small><noframes id='qYqf5'>

          <bdo id='qYqf5'></bdo><ul id='qYqf5'></ul>
        <tfoot id='qYqf5'></tfoot>

        <legend id='qYqf5'><style id='qYqf5'><dir id='qYqf5'><q id='qYqf5'></q></dir></style></legend>
      1. 检测PHP中的文件编码

        时间:2023-10-03

          • <bdo id='fq305'></bdo><ul id='fq305'></ul>
            <legend id='fq305'><style id='fq305'><dir id='fq305'><q id='fq305'></q></dir></style></legend>

            1. <i id='fq305'><tr id='fq305'><dt id='fq305'><q id='fq305'><span id='fq305'><b id='fq305'><form id='fq305'><ins id='fq305'></ins><ul id='fq305'></ul><sub id='fq305'></sub></form><legend id='fq305'></legend><bdo id='fq305'><pre id='fq305'><center id='fq305'></center></pre></bdo></b><th id='fq305'></th></span></q></dt></tr></i><div id='fq305'><tfoot id='fq305'></tfoot><dl id='fq305'><fieldset id='fq305'></fieldset></dl></div>
                <tfoot id='fq305'></tfoot>
                  <tbody id='fq305'></tbody>

                <small id='fq305'></small><noframes id='fq305'>

                  本文介绍了检测PHP中的文件编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个脚本将多个文件合并为一个,当其中一个文件具有 UTF8 编码时它会中断.我想我应该在读取文件时使用 utf8_decode() 函数,但我不知道如何判断哪个需要解码.

                  I have a script which combines a number of files into one, and it breaks when one of the files has UTF8 encoding. I figure that I should be using the utf8_decode() function when reading the files, but I don't know how to tell which need decoding.

                  我的代码基本上是:

                  $output = '';
                  foreach ($files as $filename) {
                      $output .= file_get_contents($filename) . "
                  ";
                  }
                  file_put_contents('combined.txt', $output);
                  

                  目前,在 UTF8 文件的开头,它会在输出中添加以下字符:

                  Currently, at the start of a UTF8 file, it adds these characters in the output: 

                  推荐答案

                  尝试使用 mb_detect_encoding 函数.此函数将检查您的字符串并尝试猜测"其编码是什么.然后,您可以根据需要对其进行转换.但是,正如 brulak 建议的,您最好转换to UTF-8 而不是 from,以保留您正在传输的数据.

                  Try using the mb_detect_encoding function. This function will examine your string and attempt to "guess" what its encoding is. You can then convert it as desired. As brulak suggested, however, you're probably better off converting to UTF-8 rather than from, to preserve the data you're transmitting.

                  这篇关于检测PHP中的文件编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 PHP 中迭代 UTF-8 字符串? 下一篇:PHP 中 ord 或 charCodeAt() 的 UTF-8 安全等价物

                  相关文章

                  最新文章

                  <i id='d30YG'><tr id='d30YG'><dt id='d30YG'><q id='d30YG'><span id='d30YG'><b id='d30YG'><form id='d30YG'><ins id='d30YG'></ins><ul id='d30YG'></ul><sub id='d30YG'></sub></form><legend id='d30YG'></legend><bdo id='d30YG'><pre id='d30YG'><center id='d30YG'></center></pre></bdo></b><th id='d30YG'></th></span></q></dt></tr></i><div id='d30YG'><tfoot id='d30YG'></tfoot><dl id='d30YG'><fieldset id='d30YG'></fieldset></dl></div>
                  1. <small id='d30YG'></small><noframes id='d30YG'>

                    • <bdo id='d30YG'></bdo><ul id='d30YG'></ul>

                  2. <legend id='d30YG'><style id='d30YG'><dir id='d30YG'><q id='d30YG'></q></dir></style></legend>
                      <tfoot id='d30YG'></tfoot>