How to remove multiple UTF-8 BOM sequences(如何删除多个 UTF-8 BOM 序列)
问题描述
使用 PHP5 (cgi) 从文件系统输出模板文件并且在输出原始 HTML 时遇到问题.
Using PHP5 (cgi) to output template files from the filesystem and having issues spitting out raw HTML.
private function fetch($name) {
$path = $this->j->config['template_path'] . $name . '.html';
if (!file_exists($path)) {
dbgerror('Could not find the template "' . $name . '" in ' . $path);
}
$f = fopen($path, 'r');
$t = fread($f, filesize($path));
fclose($f);
if (substr($t, 0, 3) == b'xefxbbxbf') {
$t = substr($t, 3);
}
return $t;
}
即使我添加了 BOM 修复,我仍然遇到 Firefox 接受它的问题.您可以在此处查看实时副本:http://ircb.in/jisti/(以及模板文件我如果你想检查它,请扔在 http://ircb.in/jisti/home.html出)
Even though I've added the BOM fix I'm still having problems with Firefox accepting it. You can see a live copy here: http://ircb.in/jisti/ (and the template file I threw at http://ircb.in/jisti/home.html if you want to check it out)
知道如何解决这个问题吗?o_o
Any idea how to fix this? o_o
推荐答案
你可以使用下面的代码去除 utf8 bom
you would use the following code to remove utf8 bom
//Remove UTF8 Bom
function remove_utf8_bom($text)
{
$bom = pack('H*','EFBBBF');
$text = preg_replace("/^$bom/", '', $text);
return $text;
}
这篇关于如何删除多个 UTF-8 BOM 序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何删除多个 UTF-8 BOM 序列
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01