Bonjour,

j'ai suivi le petit tuto pour récupérer mes derniers tweet -> http://www.grafikart.fr/tutoriels/php/afficher-dernier-tweet-100

Voici mon code

require "php/twitteroauth.php";
$connect_twitter = new TwitterOAuth(get_option('api-key'),get_option('api-secret'),get_option('acces-token'),get_option('acces-secret'));
$tweets = $connect_twitter->get('statuses/user_timeline', array(
    'count'=> get_option('count-get-tweet'),
));
foreach ($tweets as $key => $tweet) {
    ?>
    <p><?php echo $tweet->text; ?></p>
    <?php
}

Le seul truc c'est que ce qui est affiché n'est que du texte brut ... Comment faire pour le " formater " afin de rajouter les liens sur les éventuels url, hashtag, ... ?

Merci d'avance pour le coup de main :)

1 réponse


Joouul
Auteur

FANTASTIQUE =D

j'ai adapté en ajoutant pour les hashtags et voili voulou

require "php/twitteroauth.php";
$connect_twitter = new TwitterOAuth(get_option('api-key'),get_option('api-secret'),get_option('acces-token'),get_option('acces-secret'));
$tweets = $connect_twitter->get('statuses/user_timeline', array(
    'count'=> get_option('count-get-tweet'),
));
foreach ($tweets as $key => $tweet) {
    $regex_url = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
    $tweet = $tweet->text;
    if(preg_match($regex_url, $tweet, $url)){
        $tweet = preg_replace($regex_url, "<a href=\"{$url[0]}\">{$url[0]}</a> ", $tweet);
    }
    $tweet = preg_replace('/(?<=^|\s)@([a-z0-9_]+)/i', '<a href="http://www.twitter.com/$1">@$1</a>', $tweet);
    $tweet = preg_replace('/(?<=^|\s)#([a-z0-9_]+)/i', '<a href="http://www.twitter.com/hashtag/$1">#$1</a>', $tweet);
    ?>
    <p><?php echo $tweet; ?></p>
    <?php
}

Un tout grand merci =D