failed to load external entity

persia_persia

New Member
I'm getting the "unable to load external entity" error on the following piece of code. It's supposed to get a twitter stream but it looks like it's failing at some point, obviously. When I put the url (https://twitter.com/statuses/user_timeline/LeisureAcademy.atom?count=10) in the browser it shows the feed just as it should.. It also looks like it is happening randomly. Sometimes working great for a few days but at some point I get the error for an hour or more before it works again.\[code\]<?php // Step 1 - Swap crearegroup for your Twitter User-name $twitterid = $TwitterAccountNaam; // Step 2 - How many tweets to you want to show? Swap 4 for how many you would like. $numberoftweets = "10"; // Step 3 - Would you like to activate links within the tweets? $tags = true; // Step 4 - Would you like to activate nofollow (Best for SEO)? $nofollow = true; // Step 5 - Would you like links to appear in a new window/tab? $target = true; // Step 6 - Would you like to show the Twitter Follow Widget button? $widget = true; // Here's the Science - futher comments can be found below function changeLink($string, $tags=false, $nofollow, $target){ if(!$tags){ $string = strip_tags($string); } else { if($target){ $string = str_replace("<a", "<a target=\"_blank\"", $string); } if($nofollow){ $string = str_replace("<a", "<a rel=\"nofollow\"", $string); } } return $string; } function getLatestTweet($xml, $tags=false, $nofollow=true, $target=true,$widget=false){ global $twitterid; $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); $x = $xmlDoc->getElementsByTagName("entry"); $tweets = array(); foreach($x as $item){ $tweet = array(); if($item->childNodes->length) { foreach($item->childNodes as $i){ $tweet[$i->nodeName] = $i->nodeValue; } } $tweets[] = $tweet; } // Here's the opening DIV and List Tags. echo "<div id=\"tweets\"><ul>\n"; foreach($tweets as $tweettag){ $tweetdate = $tweettag["published"]; $tweet = $tweettag["content"]; $tweet = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=http://stackoverflow.com/"\\2\" target=\"_blank\">\\2</a>", $tweet); $tweet = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=http://stackoverflow.com/"http://\\2\" target=\"_blank\">\\2</a>", $tweet); $tweet = preg_replace("/@(\w+)/", "<a href=http://stackoverflow.com/"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $tweet); // Usernames $tweet = preg_replace("/#(\w+)/", "<a href=http://stackoverflow.com/"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $tweet); // Hash Tags $timedate = explode("T",$tweetdate); $date = $timedate[0]; $time = substr($timedate[1],0, -1); $tweettime = (strtotime($date." ".$time))+3600; // This is the value of the time difference - UK + 1 hours (3600 seconds) $nowtime = time(); $timeago = ($nowtime-$tweettime); $thehours = floor($timeago/3600); $theminutes = floor($timeago/60); $thedays = floor($timeago/86400); if($theminutes < 60){ if($theminutes < 1){ $timemessage = "Less than 1 minute ago"; } else if($theminutes == 1) { $timemessage = $theminutes." minute ago."; } else { $timemessage = $theminutes." minutes ago."; } } else if($theminutes > 60 && $thedays < 1){ if($thehours == 1){ $timemessage = $thehours." hour ago."; } else { $timemessage = $thehours." hours ago."; } } else { if($thedays == 1){ $timemessage = $thedays." day ago."; } else { $timemessage = $thedays." days ago."; } } // Here's the list tags wrapping each tweet. echo "<li id=\"tweets\">".changeLink($tweet, $tags, $nofollow, $target)."<br />\n"; // Here's the span wrapping the time stamp. echo "<br /><span>".$timemessage."</span></li>\n"; } // Here's the closing DIV and List Tags. echo "</ul></div>"; // Here's the Twitter Follow Button Widget if($widget){ echo "<a href=http://stackoverflow.com/"https://twitter.com/" .$twitterid. "\" class=\"twitter-follow-button\" data-show-count=\"true\">Follow @" .$twitterid. "</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=http://stackoverflow.com/"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>"; } } $tweetxml = "https://twitter.com/statuses/user_timeline/" . $twitterid . ".atom?count=" . $numberoftweets; getLatestTweet($tweetxml, $tags, $nofollow, $target, $widget); ?>\[/code\]
 
Back
Top