PHP程序中utf8-bom如何避免?

WBOY
Release: 2016-06-06 20:46:22
Original
1245 people have browsed it

写了一个开源的PHP程序,有些同学下载后,用记事本修改导致文件多出utf8-bom头,程序乱码或者出错。目前体现在:(PHP输出图片时有问题,header改报文头是有问题等。)

请问怎么做才能让文件中有bom字符的时候不影响程序运行。

回复内容:

写了一个开源的PHP程序,有些同学下载后,用记事本修改导致文件多出utf8-bom头,程序乱码或者出错。目前体现在:(PHP输出图片时有问题,header改报文头是有问题等。)

请问怎么做才能让文件中有bom字符的时候不影响程序运行。

移除他们、网上找的函数,自己包装下把所有文件都处理了:

<code class="lang-php">function remove_utf8_bom($text)
{
    $bom = pack('H*','EFBBBF');
    $text = preg_replace("/^$bom/", '', $text);
    return $text;
}

//然后以后写代码的时候不要用记事本,选择可以明确指定 utf-8 without bom 的编辑器或 IDE。
</code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template