Skip to content

Instantly share code, notes, and snippets.

@tylerhall
Created April 15, 2014 21:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tylerhall/10779299 to your computer and use it in GitHub Desktop.
Save tylerhall/10779299 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";
@aqsazaid
Copy link

hello every one i need a code that can search a folder and its all files then count word and its frequency and then store in a file...process execute until all files completely searched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment