Skip to content

Instantly share code, notes, and snippets.

@Mattlk13
Forked from tylerhall/count.php
Created February 15, 2017 09:29
Show Gist options
  • Save Mattlk13/06b494d99fc69b82e39e2c3af6c16391 to your computer and use it in GitHub Desktop.
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.
<?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