php实现替换UTF-8 BOM(feff)

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:53   1263   0

批量去除BOM的程序

function replace_utf8bom( $str )
{
$charset [1] = substr ( $str ,0,1);
$charset [2] = substr ( $str ,1,1);
$charset [3] = substr ( $str ,2,1);
if (ord( $charset [1]) == 239 && ord( $charset [2]) == 187 && ord( $charset [3]) == 191)
{
return substr ( $str ,3);
}
else
{
return false;
}
}

很明显,这就是前面三个字符是固定的原因,当然可以这样判断了。。。说白了很简单,但如果不知道就真的很痛苦了。顺便说一下,它来自:http://www.phptext.net/technology.php?vid=53

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP