Blogger Export XML To Json Converter In PHP
#!/usr/bin/php <?php error_reporting(-1); $doc = new DOMDocument(); $doc->load($_SERVER['argv'][1]); $entries = $doc->getElementsByTagName('entry'); $posts = array(); $comments = array(); for ($i = 0; $i < $entries->length; $i++) { $entry = $entries->item($i); $links = $entry->getElementsByTagName('link'); for ($j = 0; $j < $links->length; $j++) { $link = $links->item($j); if ($link->getAttribute('rel') == 'alternate') { $href = $link->getAttribute('href'); if (substr($href, 0, 24) == 'http://blog.jokevn.com/2') { if (strstr($href, '#') === false) { $post = new stdClass(); $post->id = substr($href, 23); $post->title = $entry-> getElementsByTagName('title')->item(0)->textContent; $post->content = $entry->getElementsByTagName('content')-> item(0)->textContent; $post->date = $entry-> getElementsByTagName('published')->item(0)->textContent; $posts[] = $post; } else { $comment = new stdClass(); $comment->post = substr($href, 23, strpos($href, '.html') - 18); $comment->author = $entry->getElementsByTagName ('name')->item(0)->textContent; $comment->content = $entry-> getElementsByTagName('content')->item(0)->textContent; $comment->date = $entry->getElementsByTagName('published')-> item(0)->textContent; $comments[] = $comment; } } } } } file_put_contents('posts.json', json_encode($posts)); file_put_contents('comments.json', json_encode($comments));













