This little snippet show all twitter posts of a specific hashtag in PHP.


function getTweets($hash_tag) {

	$url = ''.urlencode($hash_tag) ;
	echo '<p>Connecting to <strong>'.$url.'</strong>…</p>';
	$ch = curl_init($url);
	$xml = curl_exec ($ch);
	curl_close ($ch);

	//If you want to see the response from Twitter, uncomment this next part out:
	echo '<p>Response:</p>';
	echo '<pre>'.htmlspecialchars($xml).'</pre>';

	$affected = 0;
	$twelement = new SimpleXMLElement($xml);
	foreach ($twelement->entry as $entry) {
		$text = trim($entry->title);
		$author = trim($entry->author->name);
		$time = strtotime($entry->published);
		$id = $entry->id;
		echo '<p>Tweet from '.htmlspecialchars($author).': <strong>'.htmlspecialchars($text).'</strong>  <em>Posted '.date('n/j/y g:i a',$time).'</em></p>';

	return true ;


Leave a Comment

You must be logged in to post a Review.