简体   繁体   English

缩小内容sql表中的html输出

[英]Minify html output from content sql table

On the admin page, im writing content with the CK editor, and i echo this content on my website. 在管理页面上,我使用CK编辑器编写内容,然后在我的网站上回显此内容。

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

I attach an image, you can see this content output source code. 我附上一张图片,您可以看到此内容的输出源代码。 在此处输入图片说明

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? 是否有任何php函数,我可以轻松使用?

I find some on the site, but they dont workd, or they needed php.ini config, and i dont want that. 我在网站上找到了一些,但是他们没有用,或者他们需要php.ini配置,而我不想要那个。

The best solution is turning on gzip compression on server. 最好的解决方案是在服务器上启用gzip压缩。 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. 通过php删除空格和换行符不会给您带来更好的结果,就像使用这两种技术一样,将获得99%的结果-gzip和1%-删除的空格。

But you can try something like this: 但是您可以尝试如下操作:

<div class="content"><?php echo preg_replace(
    array(
        '/ {2,}/', //remove multiply spaces 
        '/<!--.*?-->|\t|(?:\r?\n[ \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; 如果您需要从内容中删除html实体,并将其称为“最小化”,请使用html_entity_decode($content['text'])它会解码&lq; and others encoded symbols to their normal state 和其他编码符号到正常状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM