Created
April 6, 2022 14:26
-
-
Save dg/292f7f43b16ce3175342de700d0b721f to your computer and use it in GitHub Desktop.
Pair / unpair {label} counter
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 | |
$path = getcwd(); | |
echo "Scanning $path\n"; | |
$it = new RecursiveDirectoryIterator($path); | |
$it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::LEAVES_ONLY); | |
$it = new RegexIterator($it, '~\.latte$~'); | |
$countPair = 0; | |
$countUnpair = 0; | |
foreach ($it as $file) { | |
echo $file, "\n"; | |
$s = file_get_contents((string) $file); | |
$open = substr_count($s, '{label'); | |
$close = substr_count($s, '{/label'); | |
$countPair += $close; | |
$countUnpair += $open - $close; | |
} | |
echo "Pair: $countPair\n"; | |
echo "Unpair: $countUnpair\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment