Thursday, October 20, 2011

Blog posts in website

We can get blog posts of our  blogs into our websites. It easier than i thought. What you need is your blog id. You can get blog id by visiting your blog dashboard and add new posts, then look into the URL, you will get a blog-id.

The code is given below



<?php
function objectsIntoArray($arrObjData, $arrSkipIndices = array())
{
    $arrData = array();
   
    // if input is object, convert into array
    if (is_object($arrObjData)) {
        $arrObjData = get_object_vars($arrObjData);
    }
   
    if (is_array($arrObjData)) {
        foreach ($arrObjData as $index => $value) {
            if (is_object($value) || is_array($value)) {
                $value = objectsIntoArray($value, $arrSkipIndices); // recursive call
            }
            if (in_array($index, $arrSkipIndices)) {
                continue;
            }
            $arrData[$index] = $value;
        }
    }
    return $arrData;
}
//7082666587974105933 ---My  blog id
$blogDetails = file_get_contents('http://www.blogger.com/feeds/7082666587974105933/posts/default');
$blogDetails = simplexml_load_string($blogDetails);
$blogDetails = objectsIntoArray($blogDetails);
echo "<pre>";
print_r($blogDetails['entry']);
echo "</pre>";


?>