I am getting notice on line 30 that twetout is undefined variable
<?php
$username = "tomaskutaj";/*
$limit = 5;
$feed = 'http://twitter.com/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit;*/
$feed ="http://search.twitter.com/search.rss?q=@tomaskutaj";
$tweets = file_get_contents($feed);
$tweets = str_replace("&", "&", $tweets);
$tweets = str_replace("<", "<", $tweets);
$tweets = str_replace(">", ">", $tweets);
$tweet = explode("<item>", $tweets);
$tcount = count($tweet) - 1;
for ($i = 1; $i <= $tcount; $i++) {
$endtweet = explode("</item>", $tweet[$i]);
$title = explode("<title>", $endtweet[0]);
$content = explode("</title>", $title[1]);
$content[0] = str_replace("–", "—", $content[0]);
$content[0] = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="http://$2$3" target="_blank">$1$2$4</a>', $content[0]);
$content[0] = str_replace("$username: ", "", $content[0]);
$content[0] = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $content[0]);
$content[0] = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $content[0]);
$mytweets[] = $content[0];
}
$x=1;
while (list(, $v) = each($mytweets)) {
$tweetout .= "<div>$v</div>\n";
if ($x==1){
$first=$tweetout;
};
$x++;
}
if ((strstr($first,'#tomaskutaj'))&&(strstr($first,'@tomaskutaj')))
echo($first);
?>
But after I added before last while saying ‘$tweetout=”;’ it runs the script but doesnt get any output and no error either, where is the problem?
You should definitely add a
before your loop, appending to a non existing string is an error.
The reason you’re getting nothing on the screen is that $first does not contain #tomaskutaj, and the if-statement at the end requires that (and @tomaskutaj which is there) to print anything.