Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to remove PHP comment spaces from PHP files

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the PHP file how to remove the PHP comment space, the article is very detailed, has a certain reference value, interested friends must read it!

Recently, I learned from thinkphp's' RUNTIME_ALLINONE': I'm not afraid of too many caches, but I'm afraid of calling too much. Wouldn't it be beautiful to merge all the commonly used files into one file?

The code is as follows:

Function strip_whitespace ($content) {

$stripStr =''

/ / analyze the php source code

$tokens = token_get_all ($content)

$last_space = false

For ($I = 0, $j = count ($tokens); $I < $j; $iTunes +) {

If (is_string ($tokens [$I])) {

$last_space = false

$stripStr. = $tokens [$I]

}

Else {

Switch ($tokens [$I] [0]) {

/ / filter various PHP comments

Case T_COMMENT:

Case T_DOC_COMMENT:

Break

/ / filter spaces

Case T_WHITESPACE:

If (! $last_space) {

$stripStr. ='

$last_space = true

}

Break

Default:

$last_space = false

$stripStr. = $tokens [$I] [1]

}

}

}

Return $stripStr

}

The custom function effectively solves the problem that the built-in unannotated space function in php_strip_whitespace system can not be understood correctly.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development