douyangcheng4965 2016-12-25 10:51
浏览 21
已采纳

从内容sql表中缩小html输出

On the admin page, im writing content with the CK editor, and i echo this content on my website.

<div class="content"><?php echo $content['text']; ?></div>

I attach an image, you can see this content output source code. enter image description here

How can i minify or compress this generated output? I want to get smaller page size, and faster load.

Is there any php function for this, that i can use easy?

I find some on the site, but they dont workd, or they needed php.ini config, and i dont want that.

  • 写回答

1条回答 默认 最新

  • douzhendi4559 2016-12-25 11:02
    关注

    The best solution is turning on gzip compression on server. Removing spaces and line breaks via php won't give you better result, same as using both technologies will give result 99% - gzip and 1% - removed spaces.

    But you can try something like this:

    <div class="content"><?php echo preg_replace(
        array(
            '/ {2,}/', //remove multiply spaces 
            '/<!--.*?-->|\t|(?:?
    [ \t]*)+/s' //remove comments, tabs, empty lines
        ),
        array(
            ' ',
            ''
        ),
        $content['text']
    );?></div>
    

    If you need to remove html entities from content, and you call this "minify" use html_entity_decode($content['text']) this will decode &lq; and others encoded symbols to their normal state

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件