Skip to content

Instantly share code, notes, and snippets.

@printempw printempw/sum.php
Created Jan 10, 2017

Embed
What would you like to do?
Calculate the total number of comments posted last year from Diqus exported XML file.
<?php
/**
* @Author: printempw
* @Date: 2017-01-10 22:44:20
* @Last Modified by: printempw
* @Last Modified time: 2017-01-10 23:09:35
*/
$xmlString = file_get_contents('./blessing-studio-2017-01-10T14_38_39.483395-all.xml');
$xml = new SimpleXMLElement($xmlString);
$sum = 0;
foreach ($xml->post as $post) {
// do not add my comments in
if (strtotime($post->createdAt) > 1451631600 && $post->author->name != 'printempw') {
// print_r($post);
$sum++;
}
}
exit("Total comments number of last year: $sum \n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.