Удаление URL и @REPLIES из твита - PullRequest
1 голос
/ 12 июня 2009
enter code 

для ($ I = 0; $ ientry); $ я ++) {

//get the id from entry
$id = $xml->entry[$i]->id;

//explode the $id by ":"
$id_parts = explode(":",$id);

//the last part is the tweet id
$tweet_id = array_pop($id_parts);

//get the account link
$account_link = $xml->entry[$i]->author->uri;

//get the image link
$image_link = $xml->entry[$i]->link[1]->attributes()->href;

//get name from entry and trim the last ")"
$name = trim($xml->entry[$i]->author->name, ")");   

//explode $name by the rest "(" inside it
$name_parts = explode("(", $name);  

//get the real name of user from the last part
$real_name = trim(array_pop($name_parts));

//the rest part is the screen name
$screen_name = trim(array_pop($name_parts));

//get the published time, replace T & Z with " " and trim the last " "
$published_time = trim(str_replace(array("T","Z")," ",$xml->entry[$i]->published));

//get the status link
$status_link = $xml->entry[$i]->link[0]->attributes()->href;

//get the tweet 
$tweet = $xml->entry[$i]->content;

//remove <b> and </b> from the tweet. If you want to show bold keyword then you can comment this line
$tweet = str_replace(array("<b>", "</b>"),array("<p><big><big>",""), $tweet);

//get the source link
$source = $xml->entry[$i]->source;

//the result div that holds the information
echo '<div class="result" id="'. $tweet_id .'">
        <div class="profile_image"><a href="'. $account_link .'"><img src="'. $image_link .'"></a></div>
         <div class="status">
            <div class="content">
                 '. $tweet .'
            </div><br>

        </div>
      </div>';

} echo "";

в коде. Переменная $ tweet содержит текст твита, но также содержит URL-адреса, которые были написаны в твиттере, # хэштеги и @ ответы.

Я хочу удалить их из твита, и единственное, что осталось, это текстовое содержимое. Как мне это сделать?

любая помощь будет оценена. спасибо я

1 Ответ

0 голосов
/ 12 июня 2009

Простое регулярное выражение сделает это:

$cleanText = preg_replace("/[#@]\\S+/", "", $tweetText);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...