Last active
December 6, 2020 14:37
-
-
Save gent-fella-health/b784a2ccc2f06e9100bf41f6fb285e9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function deleteCommentsFromFolder($dir) | |
{ | |
$di = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); | |
$it = new RecursiveIteratorIterator($di); | |
$fileArr = []; | |
foreach ($it as $file) { | |
if (pathinfo($file, PATHINFO_EXTENSION) == 'php') { | |
ob_start(); | |
echo $file; | |
$file = ob_get_clean(); | |
$fileArr[] = $file; | |
} | |
} | |
$arr = [T_COMMENT,T_DOC_COMMENT]; | |
$count = count($fileArr); | |
for ($i=1;$i < $count;$i++) { | |
$fileStr = file_get_contents($fileArr[$i]); | |
foreach (token_get_all($fileStr) as $token) { | |
if (in_array($token[0], $arr)) { | |
$fileStr = str_replace($token[1], '', $fileStr); | |
} | |
} | |
file_put_contents($fileArr[$i], $fileStr); | |
} | |
} | |
return deleteCommentsFromFolder(__DIR__); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment