Need to validate "last tweet" script

218 views Asked by At

Have been searching for a solution for hours.

My entire WordPress theme validates, except this script I'm using to receive the last tweet:

<?php
            $twitterUsername = get_option('of_twitter_username');
            $username = $twitterUsername; // Your twitter username.
            $prefix = ""; // Prefix - some text you want displayed before your latest tweet.
            $suffix = ""; // Suffix - some text you want display after your latest tweet.
            $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";

            function parse_feed($feed) {
            $stepOne = explode("<content type=\"html\">", $feed);
            $stepTwo = explode("</content>", $stepOne[1]);
            $tweet = $stepTwo[0];
            $tweet = str_replace("&lt;", "<", $tweet);
            $tweet = str_replace("&gt;", ">", $tweet);
            return $tweet;
            }

            $twitterFeed = file_get_contents($feed);
            echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
            ?>

The error, it seems, is:

$tweet = str_replace("&gt;", ">", $tweet);

Not sure how to fix this.

Thanks for any help.

2

There are 2 answers

0
Long Ears On BEST ANSWER

Replace the two str_replace calls with:

$tweet = html_entity_decode($tweet);
0
j_freyre On

Maybe a simplier way (you don't need to parse) is to load http://search.twitter.com/search.json?q=from:the_username and make a json_decode of the result.

Then you can get the last tweet easily.