In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to remove php comments and remove space function sharing". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Although there are php_strip_whitespace methods in php5 that can return the function of PHP source code after deleting comments and spaces, in order to learn, here we provide a method of your own, and you can also remove white space and comments in the code.
The copy code is as follows:
/ * *
* remove white space and comments from the code
* @ param string $content code content
* @ return string
, /
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
Case T_START_HEREDOC:
$stripStr. = "
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.