private static function _removeAllButCode($source)
{
$commentTokens = array(T_COMMENT => true, T_INLINE_HTML => true, T_DOC_COMMENT => true);
$whiteSpaceTokens = array(T_WHITESPACE => true, T_CLOSE_TAG => true, T_OPEN_TAG => true, T_OPEN_TAG_WITH_ECHO => true);
$cleanedSource = '';
foreach (token_get_all($source) as $token) {
if (is_array($token)) {
if (isset($commentTokens[$token[0]])) {
continue;
}
if (isset($whiteSpaceTokens[$token[0]])) {
$token = "";
} else {
$token = $token[1];
}
} elseif ($token === ';') {
$token = "";
}
$cleanedSource .= $token;
}
return $cleanedSource;
}