Guest you_n_me_n_php Posted June 11, 2011 Share Posted June 11, 2011 Hi All... The code below dynamically gets up to 20 of the last tweets from my twitter page and displays them on my website. How do I make the links in the tweets clickable? Does it have to do with URL encoding? <?php $user = 'gilmeragency'; $result = PIPHP_GetTweets($user); if (!$result[0]) echo 'Failed'; for ($j = 0 ; $j < $result[0] ; ++$j) { if ($j < 10) echo $result[1] [$j] . "<br />"; } function PIPHP_GetTweets ($gilmeragency) { $url = "http://twitter.com/statuses/user_timeline/$gilmeragency.xml"; $file = @file_get_contents($url); if (!strlen($file)) return array(FALSE); $xml = @simplexml_load_string($file); if ($xml == FALSE) return array(FALSE); $tweets = array(); foreach ($xml->status as $tweet) { $timestamp = strtotime($tweet->created_at); $tweets[] = "9" . date("M jS, g:ia", $timestamp) . ") " . $tweet->text; } return array(count($tweets), $tweets); } ?> Thanks! Link to comment Share on other sites More sharing options...
HartleySan Posted June 11, 2011 Share Posted June 11, 2011 Use a tags and set the href attributes to the URLs to the tweets. For example: echo '<a href="' . $sURL . '">A tweet</a>'; Sorry if my explanation is lacking. 1 Link to comment Share on other sites More sharing options...
Guest you_n_me_n_php Posted June 11, 2011 Share Posted June 11, 2011 Use a tags and set the href attributes to the URLs to the tweets. For example: echo '<a href="' . $sURL . '">A tweet</a>'; Sorry if my explanation is lacking. Thanks, Hartley. No need to apologize. I'm taking it step by step and do realize that I have to apply my own thinking to this, too. But if you would be so kind, would you please tell me where to do this in the code and why? I understand the code I have provided so far. At your leisure, please advise. Once again, I appreciate your answer... Thanks! Roland Link to comment Share on other sites More sharing options...
HartleySan Posted June 12, 2011 Share Posted June 12, 2011 Well, I'm not sure how your XML file is constructed, but I'm assuming that on each line of the file, there is a URL to a tweet, yeah? That being the case, once you parse out the URL from everything else, than you need to load each URL into a separate a tag. This could probably be accomplished from the foreach loop you already have written. Or you could write a separate loop outside of the function for going through each entry in the array, and grabbing the URL. The choice is yours. 1 Link to comment Share on other sites More sharing options...
Recommended Posts