本文介紹了如何刪除多個 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 序列的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!