Created
September 7, 2017 08:53
-
-
Save prahladyeri/d1e19d8a6d0c7ff23fe3e15f9050b6d3 to your computer and use it in GitHub Desktop.
Tool to parse disqus comments xml 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 | |
/* | |
* Tool to parse disqus comments xml file. | |
* | |
* @author Prahlad Yeri<prahladyeri@yahoo.com> | |
* @date 2017-09-06 | |
* */ | |
function find_url($root, $thid) { | |
foreach($root->thread as $thread) { | |
$curr_id = $thread->attributes("dsq", true)[0]; | |
if (strcmp($thid,$curr_id) === 0) { | |
$url = $thread->id; | |
return $url; | |
} | |
} | |
return null; | |
} | |
function parse_disqus_file($filename) { | |
$xmlstr = file_get_contents($filename); | |
$root = new SimpleXMLElement($xmlstr); | |
$posts = $root->post; | |
$cnt = 0; | |
$result = []; | |
foreach($posts as $post) { | |
$thid = ""; | |
foreach($post->thread->attributes("dsq",true) as $a=>$b) { | |
$thid = $b; | |
break; | |
} | |
$url = find_url($root, $thid); | |
$values = array( | |
"body"=>strip_tags($post->message), | |
"name"=>$post->author->name, | |
"email"=>$post->author->email, | |
//"created_at"=>date("Y-m-dTH:i:sZ", $post->created_at), | |
//"created_at"=>date_create($post->createdAt), | |
"created_at"=>$post->createdAt, | |
"url"=>$url, | |
); | |
array_push($result, $values); | |
$cnt++; | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment