| Twitter RSS on your site Works but need to be better |
henry0

msg:4421050 | 7:53 pm on Feb 23, 2012 (gmt 0) | I am playing with a few elements inherent to a class pertaining to PHP. Here is what I try to achieve: Display your own Twitter RSS on your site. FYI information your Twitter' RSS is no longer visible but still working, so to grab yours just change the username in the feed's url. The following code snippet works,(Don't pay attention to formatting) but I cannot figure how to make non active each Tweet content,the title of each tweets contains the ID so the content does not need to be a link, but I cannot figure how to do that. I also commented a link to the manual about the class. To test it just change the username, load it up and and output it in your browser. <?php // [php.net...] class CeiXML extends SimpleXMLElement{ public function asHTML(){ $ele=dom_import_simplexml($this); $dom = new DOMDocument('1.0', 'utf-8'); $element=$dom->importNode($ele,true); $dom->appendChild($element); return $dom->saveHTML(); } } echo"<table width='200'>"; //Define feed URL $feed_url = 'https://twitter.com/statuses/user_timeline/YOUR TWITTER USERNAME.rss'; //Get content of the URL $content = file_get_contents($feed_url); //Prase feeds into class $feeds = new CeiXML($content); echo '<tr><td><strong><a href="' .$feeds->channel->link.'</a><br>'. '" title="' .$feeds->channel->title. '">' .$feeds->channel->title. ' </strong></td></tr>'; echo '<tr><td><ul>'; //Output feeds foreach($feeds->channel->item as $feed2) { echo '<li><style type="text/css"> a { text-decoration:none } </style><a href="' .$feed2->link.'</a><br>">' .$feed2->title. '</li>'; } echo '</ul></td></tr>'; ?>
|
RonPK

msg:4422231 | 1:06 pm on Feb 27, 2012 (gmt 0) | | Don't pay attention to formatting |
| IMHO, it might save you some trouble... Check the HTML source of your script's output. The links are rather messy.
|
RonPK

msg:4422232 | 1:08 pm on Feb 27, 2012 (gmt 0) | Here's a hint: Replace <a href="' .$feeds->channel->link.'</a> by <a href="' .$feeds->channel->link.'">anchor text here</a>
|
henry0

msg:4422245 | 1:58 pm on Feb 27, 2012 (gmt 0) | Thanks, I am not sure I was clear enough, your solution does not offer what I try to do, as it it echoes fine all tweets example; tweet1 tweet body 1 tweet2 tweet body 2 etc... Where: tweet1 (contains link to it and tweet id) and tweet body 1 (the tweet body is also activated and I wish it to be non an activated link, just txt) it does not look good to have a whole col activated blue So how to separate the tweet's content from the top link to the tweet? I don't see how it could be done did you try to plug it and try it?
|
RonPK

msg:4422265 | 2:53 pm on Feb 27, 2012 (gmt 0) | I'd suggest using sprintf() [php.net] instead of concatenating the output; it makes it easier to code proper HTML, which I think is (at least part of) the issue here. Also, it may be useful to remove the <style> element from the loop: there is no use in having the same rule declared more than once. Tweet ID doesn't seem to be a property of $feed2, so you'll need to derive it from either $feed2->link or $feed2->guid (they're identical).
|
RonPK

msg:4424146 | 3:02 pm on Mar 2, 2012 (gmt 0) | This should get you started:
printf('<tr><td><strong><a href="%s" title="%s">%s</a></strong></td></tr>', $feeds->channel->link, $feeds->channel->title, $feeds->channel->title); echo '<tr><td><ul>'; foreach($feeds->channel->item as $item) { printf('<li><a href="%s">%s</a><br>%s</li>' . PHP_EOL, $item->link, $item->pubDate, $item->title); } echo '</ul></td></tr>'; Note that this displays the timestamp instead of the ID - seemed more useful to me.
|
henry0

msg:4424197 | 5:02 pm on Mar 2, 2012 (gmt 0) | Thanks to RonPK for adding the crucial tweaks! Note:don't know why the the boxed comments on this post are not showing as a neat rectangle. <?php ################################################################### # This snippet utilises a PHP native class.######################## # ManyThanks to Webmasterworld member RonPK for his collaboration## ################################################################### // $feed_url replace YOUR TWITTER USERNAME.rss // by your own username class CeiXML extends SimpleXMLElement{ public function asHTML(){ $ele=dom_import_simplexml($this); $dom = new DOMDocument('1.0', 'utf-8'); $element=$dom->importNode($ele,true); $dom->appendChild($element); return $dom->saveHTML(); } } echo"<table width='200'>"; //Define feed URL $feed_url = 'https://twitter.com/statuses/user_timeline/YOUR TWITTER USERNAME.rss'; //Get content of the URL $content = file_get_contents($feed_url); //Prase feeds into class $feeds = new CeiXML($content); printf('<tr><td><strong><a href="%s" title="%s">%s</a></strong></td></tr>', $feeds->channel->link, $feeds->channel->title, $feeds->channel->title); echo '<tr><td><ul>'; foreach($feeds->channel->item as $item) { printf('<li><a href="%s">%s</a><br>%s</li>' . PHP_EOL, $item->link, $item->pubDate, $item->title); } echo '</ul></td></tr></table>'; ?>
|
henry0

msg:4424205 | 5:19 pm on Mar 2, 2012 (gmt 0) | Addendum: To limit returned results, limit the foreach example is set at 2 note we use "break" $feeds = new CeiXML($content); printf('<tr><td><strong><a href="%s" title="%s">%s</a></strong></td></tr>', $feeds->channel->link, $feeds->channel->title, $feeds->channel->title); echo '<tr><td><ul>'; $i=0; foreach($feeds->channel->item as $item) { printf('<li><a href="%s">%s</a><br>%s</li>' . PHP_EOL, $item->link, $item->pubDate, $item->title); if (++$i == 2) break; } echo '</ul></td></tr></table>'; ?>
|
|
|