Get the App
SLTechnology News&Howtos  ›  Development  › 

How to remove PHP comment spaces from PHP files

Shulou Source: shulou.com Published: 2022-06-03 06:42:16 10月05日 Update

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.

Tags: Files comments spaces functions code content articles results validity value usage interests guys buddies common use suggestions methods more source code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Technology Microsoft Linux Redmi