Skip to content

Commit

Permalink
added script to remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Dec 13, 2011
1 parent fb6f449 commit c146da7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions nocomment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);

0 comments on commit c146da7

Please sign in to comment.