开发者

Need to validate "last tweet" script

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开发者_如何学Go 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.


Replace the two str_replace calls with:

$tweet = html_entity_decode($tweet);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜