forked from gabordemooij/redbean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnocomment.php
executable file
·36 lines (25 loc) · 877 Bytes
/
nocomment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
$fileStr = file_get_contents('rb.php');
$newStr = '';
function removeEmptyLines($string)
{
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);
}
$commentTokens = array(T_COMMENT);
if (defined('T_DOC_COMMENT'))
$commentTokens[] = T_DOC_COMMENT; // PHP 5
if (defined('T_ML_COMMENT'))
$commentTokens[] = T_ML_COMMENT; // PHP 4
$tokens = token_get_all($fileStr);
foreach ($tokens as $token) {
if (is_array($token)) {
if (in_array($token[0], $commentTokens))
continue;
$token = $token[1];
}
$newStr .= $token;
}
$newStr = removeEmptyLines($newStr);
$newStr = str_replace("<"."?php","",$newStr);
$newStr = "<"."?php\n//Written by Gabor de Mooij and the RedBeanPHP Community, copyright 2009-2012\n//Licensed New BSD/GPLV2 - see license.txt\n".$newStr;
file_put_contents('rbnc.php',$newStr);