Jump to content

How can I parse twitter hashtags with a certain word in?


Stuart_Westgate

Recommended Posts

At present I have wrote the code below to parse Twitter hashtags "#emotionalclothing".

 

What I really want to do is parse hashtags or status updates with any instance of the phase "emotionalclothing".

 

So say there's a word that reads "blahemotionalclothingblah" in a status update how could retrieve that status update just by searching for a regex with "emotionalclothing" in it?

 

Here's my code so far: Thanks Stuart

 

 

<?php

$pagetitle = "Pull Twitter Hashtags";

 

function getTweets($hash_tag) {

 

$url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag) ;

echo "<p>Connecting to <strong>$url</strong> ...</p>";

$ch = curl_init($url);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);

$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 ".$author.": <strong>".$text."</strong> <em>Posted ".date('n/j/y g:i a',$time)."</em></p>";

}

 

return true ;

}

 

getTweets('#emotionalclothing');

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.