Ne "RT @" bulmak için düzenli ifade olurdu?

2 Cevap

Ben twitter benim api sorgudan bu sonuçları alıyorum.

Ben tweet'leyen olanları göstermek değil istiyorum.

Nasıl PHP bunu gerçekleştirmek istiyorsunuz?

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

Şerefe :),

2 Cevap

Eğer düzenli bir ifade kullanmak gerekir, ve tweets denilen bir dizi olduğunuzu varsayarak yoksa $tweets:

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

Ayrıntılar için strpos() bakın. Biraz daha hızlı çok regexs kullanmaktan daha olabilir.

<?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);                                                                                                  

verir

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

Sadece girişleri RT @ ile başlıyor ama aynı zamanda içlerinde bir yere RT @ sahip olanlar sadece kullanmak kaldırmak istemiyorsanız:

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

Eğer kayıtlar varsa zaten ayrılmış sıradanifade kullanmayın. Sadece onlar üzerinde yineleme ve eğer strpos($entry, 'RT @') !== FALSE kontrol ve eğer, bu girdiyi kaldırın.