daileycon
01-22-2012, 05:11 PM
I've been working on this for 2 days and can't figure it out. All I want to do is show the last 5 tweets from a twitter account on my homepage. The code below works fine when I call the file by it self: http://www.mysite.com/gettwit.php
But when I try and SSI include it <!--#include virtual='gettwit.php' --> it gives me:
Warning: simplexml_load_file(http://twitter.com/statuses/user_timeline/kingjames.xml?count=5) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /hermes/web02/b1918/moo.mysitecom/gettwit.php on line 8
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://twitter.com/statuses/user_timeline/kingjames.xml?count=5" in /hermes/web02/b1918/moo.mysitecom/gettwit.php on line 8
could not connect
My homepage is .shtml and has other SSI working fine. I've tried using urlencode and it worked a few times then went back to giving this error. How does something work and then just stop working without editing the code?!!! What am I missing? Also how do I add an error handler so it shows "Cannot Connect" when it has problems? Thanks for any help. This is frustrating.
<?php
function getLastXTwitterStatus($userid,$x){
$url = 'http://twitter.com/statuses/user_timeline/'.$userid.'.xml?count='.$x.'';
///$url = urlencode($url);
$xml = simplexml_load_file($url) or die('could not connect');
echo '<ul style:text-align:left;>';
foreach($xml->status as $status){
$text = twitterify( $status->text );
echo '<li>'.utf8_decode($text).'</li>';
}
echo '</ul>';
}
function twitterify($ret) {
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" >\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" >\\2</a>", $ret);
$ret = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" >@\\1</a>", $ret);
$ret = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" >#\\1</a>", $ret);
return $ret;
}
getLastXTwitterStatus('kingjames',5);
?>
But when I try and SSI include it <!--#include virtual='gettwit.php' --> it gives me:
Warning: simplexml_load_file(http://twitter.com/statuses/user_timeline/kingjames.xml?count=5) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /hermes/web02/b1918/moo.mysitecom/gettwit.php on line 8
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://twitter.com/statuses/user_timeline/kingjames.xml?count=5" in /hermes/web02/b1918/moo.mysitecom/gettwit.php on line 8
could not connect
My homepage is .shtml and has other SSI working fine. I've tried using urlencode and it worked a few times then went back to giving this error. How does something work and then just stop working without editing the code?!!! What am I missing? Also how do I add an error handler so it shows "Cannot Connect" when it has problems? Thanks for any help. This is frustrating.
<?php
function getLastXTwitterStatus($userid,$x){
$url = 'http://twitter.com/statuses/user_timeline/'.$userid.'.xml?count='.$x.'';
///$url = urlencode($url);
$xml = simplexml_load_file($url) or die('could not connect');
echo '<ul style:text-align:left;>';
foreach($xml->status as $status){
$text = twitterify( $status->text );
echo '<li>'.utf8_decode($text).'</li>';
}
echo '</ul>';
}
function twitterify($ret) {
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" >\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" >\\2</a>", $ret);
$ret = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" >@\\1</a>", $ret);
$ret = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" >#\\1</a>", $ret);
return $ret;
}
getLastXTwitterStatus('kingjames',5);
?>