PHP函数来压缩javascript代码? [英] PHP function to compact javascript code?

查看:68
本文介绍了PHP函数来压缩javascript代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我远非PHP专家,而且我一直在努力创建一个函数

,它将采用javascript .js文件和compact它尽可能多。

含义,删除所有注释和不必要的空格。 "模糊处理"是没有必要的
。显然,压缩的javascript应该与原始的javascript一样运行




有人能指出我这样做的现有功能吗?
< br $> b $ b谢谢!


-

Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com

I am far from a PHP expert, and I''ve been struggling to create a function
which will take a javascript .js file and "compact" it as much as possible.
Meaning, remove all comments and unnecessary whitespace. "Obfuscation" is
not necessary. Obviously, the compacted javascript should run identically to
the original javascript.

Can anyone point me to an existing function that does this?

Thanks!

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com

推荐答案

Matt Kruse写道:
Matt Kruse wrote:
我远非PHP专家,而且我一直在努力创建一个函数
,它将采用javascript .js文件和compact。
可能。意思是,删除所有评论和不必要的空格。
混淆没有必要。显然,压缩的javascript应该与原始的javascript运行相同。

任何人都可以指向我这样做的现有函数吗?
I am far from a PHP expert, and I''ve been struggling to create a function
which will take a javascript .js file and "compact" it as much as
possible. Meaning, remove all comments and unnecessary whitespace.
"Obfuscation" is not necessary. Obviously, the compacted javascript should
run identically to the original javascript.

Can anyone point me to an existing function that does this?




不,但如果你是我想到的马特克鲁斯,你知道如何编程

Javascript。鉴于语法相似,您可能会发现PHP5函数

php_strip_whitespace()符合您的要求。如果没有(或者如果你是运行早期版本的
)那么...


正则表达式可用于PHP中的所有这些,虽然我可以使用str_replce来获取大部分空白内容:



No, but if you''re the Matt Kruse I''m thinking of, you know how to program in
Javascript. Given the similarity in syntax, you may find the PHP5 function
php_strip_whitespace() meets your requirements. If not (or if you''re
running an earlier version) then...

Regular expressions can be used for all of this in PHP, although I''d
probably use str_replce for most of the whitespace stuff:


js = str_replace(" \ t",'''',
js=str_replace("\t", '' '',


js); //标签字符
js); // tab chars


这篇关于PHP函数来压缩javascript代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆