Another script that I have been using for a while is a script to allow me to search Twitter.

Twitter is another page that is blocked at work and as someone who has an interest in what is going on in the world this dissapoints me.

The script has four variables U: username, N: number of tweets to pull back, H: hashtag and S: search. It will be interesting to see if the PHP plugin handles GET data in a WordPress post.

echo " ";
echo "

";
$username = $_GET["u"]; // twitter username to search for
$tweetnum = $_GET["n"]; // number of tweets to pull back
$hashtag  = $_GET["h"]; // hashtag to search for
$searchid = $_GET["s"]; // search term to search for
$i = 1;

if ($username != "")  { // check to see if username is supplied
if ($tweetnum === "" || !isset($tweetnum)){ // if tweetum is not set then use 10
$tweetnum = "10";
}
echo "
<h1>" . $tweetnum . " Tweets From " . htmlspecialchars($username, ENT_QUOTES) . "</h1>
"; // Print page header
echo "
<div class="tweets">";
// get the twitter feed
$feed = @file_get_contents("http://search.twitter.com/search.atom?q=from:" . htmlspecialchars($username, ENT_QUOTES) . "&rpp=" . htmlspecialchars($tweetnum, ENT_QUOTES)); // get the twitter feed

$stepOne = explode("", $feed);
while ($i < count($stepOne)){ // we set i to start at one to miss the first line of junk
$stepTwo = explode("", $stepOne[$i]);

$tweet = $stepTwo[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
$tweet = str_replace("&", "&", $tweet);
$tweet = str_replace("'", "'", $tweet);
$tweet = str_replace(""", "", $tweet); //blank the quote
$tweet = str_replace("#fb", "", $tweet);
$tweet = str_replace(""", "", $tweet); // just in case the other type crops up
$tweet = str_replace("http://twitter.com/","http://www.robmcghee.com/programming/twitter-searching/?n=10&u=",$tweet); // replace twitter domain for links
$tweet = str_replace("http://search.twitter.com/search?q=%23","http://www.robmcghee.com/programming/twitter-searching/?h=",$tweet);
$tweet = str_replace("href=http://twitpic.com","href=http://m0usey.appspot.com/twitpic.com",$tweet);
$tweet = str_replace("href=http://yfrog.com","href=http://m0usey.appspot.com/yfrog.com",$tweet);
$tweet = str_replace("href=http://plixi.com","href=http://m0usey.appspot.com/plixi.com",$tweet);

if ($tweet != ""){ // stop a blank line appearing first off
echo $tweet . "

"; // print the tweet
}
$i++; // increase i to fetch the next tweet
}
}elseif ($hashtag != ""){
echo "
<h1>Tweets With Hashtag #" . htmlspecialchars($hashtag, ENT_QUOTES) . "</h1>
"; // Print the page header
echo "
<div class="tweets">";
// get the twitter feed
$feed = @file_get_contents("http://search.twitter.com/search.atom?q=%23" . htmlspecialchars($hashtag, ENT_QUOTES)); // get the twitter feed

$stepOne = explode("", $feed);
while ($i < count($stepOne)){ // we set i to start at one to miss the first line of junk
$stepTwo = explode("", $stepOne[$i]);

$tweet = $stepTwo[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
$tweet = str_replace("&", "&", $tweet);
$tweet = str_replace("'", "'", $tweet);
$tweet = str_replace(""", "", $tweet); //blank the quote
$tweet = str_replace("#fb", "", $tweet);
$tweet = str_replace(""", "", $tweet); // just in case the other type crops up
$tweet = str_replace("http://twitter.com/","http://www.robmcghee.com/programming/twitter-searching/?n=10&u=",$tweet); // replace twitter domain for links
$tweet = str_replace("http://search.twitter.com/search?q=%23","http://www.robmcghee.com/programming/twitter-searching/?h=",$tweet);

if ($tweet != ""){ // stop a blank line appearing first off
echo $tweet . "

"; // print the tweets
}
$i++; // increase i to fetch the next tweet
}
}elseif ($searchid != ""){
echo "
<h1>Tweets Mentioning: '" . htmlspecialchars($searchid, ENT_QUOTES) . "'</h1>
"; // Print the header
echo "
<div class="tweets">";
// get the twitter feed
$feed = @file_get_contents("http://search.twitter.com/search.atom?q=" . str_replace(" ","+", htmlspecialchars($searchid, ENT_QUOTES))); // get the twitter feed

$stepOne = explode("", $feed);
while ($i < count($stepOne)){ // we set i to start at one to miss the first line of junk
$stepTwo = explode("", $stepOne[$i]);

$tweet = $stepTwo[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
$tweet = str_replace("&", "&", $tweet);
$tweet = str_replace("'", "'", $tweet);
$tweet = str_replace(""", "", $tweet); //blank the quote
$tweet = str_replace("#fb", "", $tweet);
$tweet = str_replace(""", "", $tweet); // just in case the other type crops up
$tweet = str_replace("http://twitter.com/","http://www.robmcghee.com/programming/twitter-searching/?n=10&u=",$tweet); // replace twitter domain for links
$tweet = str_replace("http://search.twitter.com/search?q=%23","http://www.robmcghee.com/programming/twitter-searching/?h=",$tweet);

if ($tweet != ""){ // stop a blank line appearing first off
echo $tweet . "

"; // print the tweet
}
$i++; // increase i to fetch the next tweet
}
}else{
// display a message if none of the options have been used
echo "Please enter a Twitter Username for this page to work
";
echo "<a href="http://www.robmcghee.com/programming/twitter-searching/?u=llygoden&n=10">http://www.robmcghee.com/programming/twitter-searching/?u=llygoden&n=10</a>";
}

echo "

</div>
<form action="http://www.robmcghee.com/programming/twitter-searching/" method="get"> <input name="u" type="text" /> <strong>U</strong>
<input maxlength="2" name="n" size="1" type="text" value="10" /> <strong>N</strong>
<input name="h" type="text" /> <strong>H</strong>
<input name="s" type="text" /> <strong>S</strong>
<input type="submit" value="Go" /> </form>
<div class="stream"><a href="http://www.robmcghee.com/programming/twitter-stream/"><strong>MY STREAM</strong></a></div>
</div>
</div>
";		?>