-
-
Save Mattlk13/06b494d99fc69b82e39e2c3af6c16391 to your computer and use it in GitHub Desktop.
A quick PHP script to count the total number of words written in your Day One journal file.
This file contains 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 | |
$journal_fn = $argv[1]; | |
$entries_dir = $journal_fn . '/entries/'; | |
$entries = scandir($entries_dir); | |
print_r($entries); | |
$total_words = 0; | |
foreach($entries as $e) | |
{ | |
if(substr($e, strlen($e) - 8) == '.doentry') | |
{ | |
$fn = $entries_dir . '/' . $e; | |
$xml = simplexml_load_file($fn); | |
$text = $xml->dict->string; | |
echo $fn . ' - ' . str_word_count((string)$text) . "\n"; | |
$total_words += str_word_count((string)$text); | |
} | |
} | |
echo "Total words: $total_words\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment