note 115538 deleted from tokenizer.examples by salathe
| From: | salathe@php.net | Date: | Fri, 22 Aug 2014 08:07:10 +0000 |
| Subject: | note 115538 deleted from tokenizer.examples by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-200249@lists.php.net to get a copy of this message | ||
Note Submitter: anant kumar singh
----
<?php
$fileStr = file_get_contents('filepath');
$newStr = '';
$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;
}
$newfile = file_put_contents('newfilename',$newStr);
//echo $newStr;die;
?>