替换“//"带有“/* */"在 PHP 中? [英] Replace "//" with "/* */" in PHP?
本文介绍了替换“//"带有“/* */"在 PHP 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写代码来缩小 html/css/js,但我遇到了问题.
I'm working in a code to minify html/css/js but i got a problem.
我需要用/* 和 */替换//.
I need to replace // with /* and */.
示例:
$(funcion(){
// Do something
});
替换为:
$(funcion(){
/* Do something */
});
怎么做?
推荐答案
首先,正如评论中所指出的,如果您希望减小大小,则应删除评论.
First, as was pointed out in the comments, if you're looking to reduce the size, comments should be stripped.
function convertComment(str){
if(str.substring(0,2) === '//'){
str = '/*' + str.substring(2) + ' */';
} else {
str = false;
}
return str;
}
您的示例代码看起来像 JQuery,所以如果您正在寻找 PHP,这里是那个版本:
Your example code looked like JQuery, so if you were looking for PHP, here is that version:
function convertComment($s){
if(substr($s,0,2) == '//'){
$s = '/*' . substr($s,2) . ' */';
} else {
$s = false;
}
return $s;
}
这篇关于替换“//"带有“/* */"在 PHP 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文