Skip to content

Instantly share code, notes, and snippets.

@dg
Created April 6, 2022 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dg/292f7f43b16ce3175342de700d0b721f to your computer and use it in GitHub Desktop.
Save dg/292f7f43b16ce3175342de700d0b721f to your computer and use it in GitHub Desktop.
Pair / unpair {label} counter
<?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