压缩php代码,删除多余空白注释,无用空格,比TP处理彻底<?php <br />
/** <br>
* @Author 70(QQ781787584)<br>
* <br>
* @link http://www.qiling.org <br>
* <br>
* @Copyright 2014-12-09 00:32:10 <br>
* <br>
*/<br>
header ( "Content-type: text/html; charset=utf-8" );<br>
// $content = file_get_contents ( 'demo.php' );<br>
$content = file_get_contents ( __FILE__ );<br>
$result = token_get_all ( $content );<br>
<br>
// 遍历数组 使用指针<br>
$string = '';<br>
$space = false;<br>
// print_r($result);<br>
<br>
while ( current ( $result ) ) {<br>
$value = current ( $result );<br>
if (is_string ( $value )) {<br>
// 去掉字符左侧的 空白<br>
if ($space) {<br>
$string = rtrim ( $string ) . $value;<br>
} else {<br>
$string .= $value;<br>
}<br>
// 去掉字符右侧的 空白 添加一个标记 如果为 True需要删除右侧的空白 如果 为 false 不需要删除右侧的空白<br>
$space = true;<br>
} else {<br>
switch ($value [0]) {<br>
// 去掉php开始标记中的空格<br>
case T_OPEN_TAG :<br>
$string .= trim ( $value [1] ) . ' ';<br>
//这样做了能删除各种注释下的多余空格 如果没有下边这句会造成有多余空格 如 <?php /**/,<?php // , <?php echo <br />
//虽然我这样做了 ^_^ 但是我没想明白...<br>
$space = true;<br>
break;<br>
// 把空白字符全部转换为 空格<br>
case T_WHITESPACE :<br>
if ($space == false) {<br>
$string .= ' ';<br>
$space = true;<br>
}<br>
break;<br>
// 去掉注释<br>
case T_DOC_COMMENT :<br>
$space = true;<br>
break;<br>
// 去掉注释<br>
case T_COMMENT :<br>
$space = true;<br>
break;<br>
// 判断定界符开始<br>
case T_START_HEREDOC :<br>
$space = false;<br>
$string .= "
break;<br>
// 判断定界符结束<br>
case T_END_HEREDOC :<br>
$space = true;<br>
$string .= "S;\n";<br>
//因为这里取到的值是不带 分号 ; 的 这里直接 跳过下个元素的处理 注:不知道会不会存在问题 测试没问题<br>
next ( $result );<br>
<br>
break;<br>
default :<br>
// 去掉某些 左右 的空白 你可以添加更多你认为两边可以删除空白的标记 目前我找到这些<br>
$array = array (<br>
T_CONCAT_EQUAL, // .=<br>
T_DOUBLE_ARROW, // =><br>
T_BOOLEAN_AND, // &&<br>
T_BOOLEAN_OR, // ||<br>
T_IS_EQUAL, // ==<br>
T_IS_NOT_EQUAL, // != or <br>
T_IS_SMALLER_OR_EQUAL, //
T_IS_GREATER_OR_EQUAL, // >=<br>
T_INC, // ++<br>
T_DEC, // --<br>
T_PLUS_EQUAL, // +=<br>
T_MINUS_EQUAL, // -=<br>
T_MUL_EQUAL, // *=<br>
T_DIV_EQUAL, // /=<br>
T_IS_IDENTICAL, // ===<br>
T_IS_NOT_IDENTICAL, // !==<br>
T_DOUBLE_COLON, // ::<br>
T_PAAMAYIM_NEKUDOTAYIM, // ::<br>
T_OBJECT_OPERATOR, // -><br>
T_DOLLAR_OPEN_CURLY_BRACES, // ${<br>
T_AND_EQUAL, // &=<br>
T_MOD_EQUAL, // %=<br>
T_XOR_EQUAL, // ^=<br>
T_OR_EQUAL, // |=<br>
T_SL, //
T_SR, // >><br>
T_SL_EQUAL, //
T_SR_EQUAL // >>=<br>
);<br>
<br>
if (in_array ( $value [0], $array )) {<br>
$string = rtrim ( $string ) . $value [1];<br>
;;;;;;;;;;; //有强迫症的可以继续删除 多余 的分号 我就不删除了<br>
} else {<br>
$string .= $value [1];<br>
}<br>
$space = in_array ( $value [0], $array );<br>
break;<br>
}<br>
}<br>
next ( $result );<br>
}<br>
<br>
echo $string;
转载注明我的博客地址:http://www.qiling.org
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor
