Javascript 如何在html中压缩动态代码?
大家好,有人能帮我压缩html5、css3和php中的动态代码吗?对于运行在服务器端的php“代码”来说是无用的Javascript 如何在html中压缩动态代码?,javascript,php,html,Javascript,Php,Html,大家好,有人能帮我压缩html5、css3和php中的动态代码吗?对于运行在服务器端的php“代码”来说是无用的 对于html、css、javascript,您可以为您的任务安装一些专用插件,例如缩小css和缩小html。如果您进行了谷歌搜索,您应该已经找到: 正如其他人所指出的,您可以使用任务运行程序来缩小CSS和JS 同时,您的问题被错误地标记,因为它与JavaScript没有关系。 <?php /* start the output buffer */
对于html、css、javascript,您可以为您的任务安装一些专用插件,例如缩小css和缩小html。如果您进行了谷歌搜索,您应该已经找到:
正如其他人所指出的,您可以使用任务运行程序来缩小CSS和JS
同时,您的问题被错误地标记,因为它与JavaScript没有关系。
<?php
/* start the output buffer */
ob_start('compress_page');
/* xhtml code below */
/* end the buffer, echo the page content */
ob_end_flush('compress_page');
/* function that gets rid of tabs, line breaks, and extra spaces */
function compress_page($buffer) {
// remove comments, tabs, spaces, newlines, etc.
$search = array(
"/\/\*(.*?)\*\/|[\t\r\n]/s" => "",
"/ +\{ +|\{ +| +\{/" => "{",
"/ +\} +|\} +| +\}/" => "}",
"/ +: +|: +| +:/" => ":",
"/ +; +|; +| +;/" => ";",
"/ +, +|, +| +,/" => ","
);
$buffer = preg_replace(array_keys($search), array_values($search), $buffer);
return $buffer;
}
?>
最后工作了^ ^压缩是什么意思?动态代码是什么意思?代码是什么意思?帮助是什么意思?我的意思是当你在一个页面中查看页面源代码时,没有空格,非常感谢。只处理HTML和JS如果它对你有用或者引导你找到解决方案,那么你应该接受这一点作为答案
<?php
/* start the output buffer */
ob_start('compress_page');
/* xhtml code below */
/* end the buffer, echo the page content */
ob_end_flush('compress_page');
/* function that gets rid of tabs, line breaks, and extra spaces */
function compress_page($buffer) {
// remove comments, tabs, spaces, newlines, etc.
$search = array(
"/\/\*(.*?)\*\/|[\t\r\n]/s" => "",
"/ +\{ +|\{ +| +\{/" => "{",
"/ +\} +|\} +| +\}/" => "}",
"/ +: +|: +| +:/" => ":",
"/ +; +|; +| +;/" => ";",
"/ +, +|, +| +,/" => ","
);
$buffer = preg_replace(array_keys($search), array_values($search), $buffer);
return $buffer;
}
?>