How to remove multiple UTF-8 BOM sequences

后端 未结 11 2034
故里飘歌
故里飘歌 2020-11-22 10:28

Using PHP5 (cgi) to output template files from the filesystem and having issues spitting out raw HTML.

private function fetch($name) {
    $path = $this->         


        
11条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 11:14

    When working with faulty software it happens that the BOM part gets multiplied with every saving.

    So I am using this to get rid of it.

    function remove_utf8_bom($text) {
        $bom = pack('H*','EFBBBF');
        while (preg_match("/^$bom/", $text)) {
            $text = preg_replace("/^$bom/", '', $text);
        }
        return $text;
    }
    

提交回复
热议问题