This is a companion article to a JavaScript version of the same tutorial. This article is intended for PHP developers who want to pull WordPress and other blog posts into a non-Wordpress or non-blog web page.

If you are using PHP, I recommend you use this method, as it is cleaner than JavaScript and completed entirely at server-side.

The Google feeds API accomodates a wide range of scripting languages. You can view the See the other languages’ examples documentation here.

Quick and Easy RSS Feed Import

Simply enter the 2 URLS- your page and the page of the feed.

$referer = ""; // your website, of course!
$feedurl = ""; // the feed location!
$apiurl = "$feedurl&userip=$ip;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$body = curl_exec($ch);
$results = json_decode($body);

All PHP calls to the Google API must follow the rules! Refer to Google’s notes on the API

Applications MUST always include a valid and accurate HTTP referer header in their requests.

We highly encourage you to include the userip parameter (not required, but highly encouraged). This parameter supplies the IP address of the end-user who made the request and validates that you are not making automated requests in violation of the Terms of Service.

Results Object

$results is a PHP object containing the following information:

[responseData] => stdClass Object
    [feed] => stdClass Object
        [feedUrl] =>
        [title] =>
        [link] =>
        [author] => 
        [description] => Hardware. Software. Solid.
        [type] => rss20
        [entries] => Array
            [0] => stdClass Object
                [title] => iPhone/iPod Touch Add Photo or Video to Email
                [link] =>
                [author] => SolidlyStated
                [publishedDate] => Sat, 29 Sep 2012 16:11:10 -0700
                [contentSnippet] => Adding photo attachments to an email seem like such...
                [content] => <p>Adding photo attachments to an email seem like such...</p>
                    <p>Last paragraph of content.</p>
                [categories] => Array
                    [0] => Hardware
                    [1] => Apple
                    [2] => email
                    [3] => iPhone
                    [4] => iPod Touch
            [1] => stdClass Object
                ... more articles ...
[responseDetails] => 
[responseStatus] => 200

The Results Object

Notice that you will get a “responseStatus” property in your $results variable. A good response will have a 200 status. You can easily avoid errors if it gives you a bad response using this check.

The $results object will contain multiple posts and you can use PHP to loop through and use what you want.

Similar to the JavaScript feed API from Google, the categories property will contain both the actual blog category and the post tags as well. This makes the category less than helpful for display purposes.