0

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.

Amir Raminfar
  • 33,777
  • 7
  • 93
  • 123
Justin
  • 143
  • 2
  • 7
  • an attribute value must be a literal unless it contains only name characters * Line 274, column 62: an attribute value must be a literal unless it contains only name characters … Miniml WordPress Theme http://i… – Justin Feb 24 '11 at 20:47
  • Here's a better view of the error message: http://i.imgur.com/6Wp25.png – Justin Feb 24 '11 at 20:49

2 Answers2

1

Replace the two str_replace calls with:

$tweet = html_entity_decode($tweet);
Long Ears
  • 4,886
  • 1
  • 21
  • 16
0

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.

j_freyre
  • 4,623
  • 2
  • 30
  • 47