tags:

views:

35

answers:

3

I am getting these results from my api query on twitter.

I would like to not display the Retweeted ones.

How would i accomplish this in PHP?

RT @BarclaysWealth: RT @BarclaysStock: Investment ViewPoint - We take a look at what a hung parliament could mean for the UK economy http://bit.ly/OaYh7
From: InfoFocus: at: Fri, 07 May 2010 21:02:10 +0000

RT @BarclaysStock: Investment ViewPoint - We take a look at what a hung parliament could mean for the UK economy http://bit.ly/OaYh7
From: BARXdirect: at: Fri, 07 May 2010 16:35:56 +0000

Investment ViewPoint - We take a look at what a hung parliament could mean for the UK economy http://bit.ly/OaYh7
From: BarclaysStock: at: Fri, 07 May 2010 16:35:12 +0000

Cheers :),

+2  A: 
$text = 'RT @BarclaysWealth: RT @BarclaysStock: Investment ViewPoint...';
if (preg_match('/^RT @/', $text)) {
 // this one starts with  RT @
} else {
 // does not start with RT @, so do something with it
}
rikh
This won't account for RT's that have a comment at the front eg "This is cool RT @foo some text".
richsage
Just drop the ^ in the regex if you want to allow it anywhere.
rikh
+3  A: 

If you don't need to use a regular expression, and assuming your tweets are in an array called $tweets:

foreach ($tweets as $tweet)
{
  if (strpos($tweet, "RT @") === FALSE)
  {
    print $tweet;
  }
}

See strpos for details. Might be a tad faster than using regexs too.

richsage
Your example is good, just inverted. He wants to print the non-RT ones. :)
treznik
Gah. Quick answer fail! :-) I'll update :-)
richsage
A: 
<?php                                                                                                                                                             
$d = 'RT @BarclaysWealth: RT @BarclaysStock: Investment ViewPoint - We take a look at what a hung parliament could mean for the UK economy http://bit.ly/
From: InfoFocus: at: Fri, 07 May 2010 21:02:10 +0000                                                                                                     

RT @BarclaysStock: Investment ViewPoint - We take a look at what a hung parliament could mean for the UK economy http://bit.ly/OaYh7                     
From: BARXdirect: at: Fri, 07 May 2010 16:35:56 +0000                                                                                                    

Investment ViewPoint - We take a look at what a hung parliament could mean for the UK economy http://bit.ly/OaYh7                                        
From: BarclaysStock: at: Fri, 07 May 2010 16:35:12 +0000                                                                                                 

';                                                                                                                                                       

echo preg_replace('/(^|(?<=\n))RT @.*?\n\n/s', '', $d);                                                                                                  

gives

Investment ViewPoint - We take a look at what a hung parliament could mean for the UK economy http://bit.ly/OaYh7
From: BarclaysStock: at: Fri, 07 May 2010 16:35:12 +0000

If you don't want to remove only entries starting with RT @ but also the ones that have RT @ somewhere inside them use just:

echo preg_replace('/RT @.*?\n\n/s', '', $d);

If you have your entries already separated don't use regexp. Just iterate over them and check if strpos($entry, 'RT @') !== FALSE and if it does, remove this entry.

Kamil Szot