douxueke5653 2017-09-05 05:31
浏览 78
已采纳

特殊字符显示无效

I am using a way to compress HTML on fly. Below is the function

function compress_page($buffer) {
    $search = array(
        '/\>[^\S ]+/s', /*strip whitespaces after tags, except space*/
        '/[^\S ]+\</s', /*strip whitespaces before tags, except space*/
        '/(\s)+/s',  /*shorten multiple whitespace sequences*/
    );
    $replace = array(
        '>',
        '<',
        '\\1',
    );
    $buffer = preg_replace($search, $replace, $buffer);
    return $buffer;
}

function is working but the problem is, after implement this, germam characters are not showing anymore. They are showing like "�". Can you please help me to find problem. I tried other ways to minify HTML but get same proble.

  • 写回答

2条回答 默认 最新

  • doubi1931 2017-09-05 06:23
    关注

    After research, I found this solution. This will minify full html in one line.

    function pt_html_minyfy_finish( $html )  {
      $html = preg_replace('/<!--(?!s*(?:[if [^]]+]|!|>))(?:(?!-->).)*-->/s', '', $html);
      $html = str_replace(array("
    ", "", "
    ", "\t"), '', $html);
      while ( stristr($html, '  '))
         $html = str_replace('  ', ' ', $html);
     return $html;
    }
    

    Hope this will help someone!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器