steelmanronald06 Posted November 5, 2009 Share Posted November 5, 2009 Okay, here's the deal. I think my eyes are crossing from working on the computer for the past 6 hours (google maps api, twitter, etc). Very frustrating. Anyways, I'm having a problem that I think revolves with explode(). Go to: http://www.oldhatcreative.com/newohtestground/twitter/ Okay now hover over a link for someone. Lets say oldhatcreative. The link reads: http://www.twitter.com/oldhatcreative</uri> </author> Obviously I don't want it to read like that, but I can't see to figure out how to strip out that </uri> </author>. By all accounts it should be there. Second problem. Hover over any of the links in the actual tweets. They display as: http://www.oldhatcreative.com/newohtestground/twitter/"http://linkdomain.tld" I want links to parse as normal html links...and they should. If you go to http://search.twitter.com/search.atom?q=from%3aoldhatcreative and View Source, you'll see that twitter nicely puts that stuff into <a href="">...</a> tags for me! Now for my code. <?php /* Relative Time Function based on code from http://stackoverflow.com/questions/11/how-do-i-calculate-relative-time/501415#501415 For use in the "Parse Twitter Feeds" code below */ define("SECOND", 1); define("MINUTE", 60 * SECOND); define("HOUR", 60 * MINUTE); define("DAY", 24 * HOUR); define("MONTH", 30 * DAY); function relativeTime($time) { $delta = strtotime('+2 hours') - $time; if ($delta < 2 * MINUTE) { return "1 min ago"; } if ($delta < 45 * MINUTE) { return floor($delta / MINUTE) . " min ago"; } if ($delta < 90 * MINUTE) { return "1 hour ago"; } if ($delta < 24 * HOUR) { return floor($delta / HOUR) . " hours ago"; } if ($delta < 48 * HOUR) { return "yesterday"; } if ($delta < 30 * DAY) { return floor($delta / DAY) . " days ago"; } if ($delta < 12 * MONTH) { $months = floor($delta / DAY / 30); return $months <= 1 ? "1 month ago" : $months . " months ago"; } else { $years = floor($delta / DAY / 365); return $years <= 1 ? "1 year ago" : $years . " years ago"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <?php // Pull multiple acccounts by listing here. Seperate with a space $usernames = "dustinschmidt OldHatCreative ixdeb xxghostxx"; // Number of tweets to pull, IN TOTAL! $limit = "15"; // Show usernames? 0=No, 1=Yes $show = 1; // POI: When using HTML, escape double-quotations like this: \" // This comes before the entire block of tweets $prefix = "<h1>Old Hat Twitter Feeds</h1><ul>"; // This comes before each tweet on the feed. $prefix_sub = "<li>"; // This comes after the username but before the tweet content. $wedge = " says: "; $suffix_sub = "</li>"; // This comes after the entire block of tweets. $suffix = "</ul>"; // POI: Beyond here, have good PHP knowledge before altering function parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub) { // Use some regex to get the usernames correct $usernames = str_replace(" ", "+OR+from%3A", $usernames); // Push that into the feed $feed = "http://search.twitter.com/search.atom?q=from%3a" . $usernames . "&rpp=" . $limit; $feed = file_get_contents($feed); $feed = str_replace("&", "&", $feed); $feed = str_replace("&alt;a href="", "<a href=\"", $feed); $feed = str_replace("">", "\">", $feed); $feed = str_replace("</a>", "</a>", $feed); $feed = str_replace("<", "<", $feed); $feed = str_replace(">", ">", $feed); $clean = explode("<entry>", $feed); $amount = count($clean) - 1; for ($i = 1; $i <= $amount; $i++) { $entry_close = explode("</entry>", $clean[$i]); $clean_content_1 = explode("<content type=\"html\">", $entry_close[0]); $clean_content = explode("</content>", $clean_content_1[1]); $clean_name_2 = explode("<name>", $entry_close[0]); $clean_name_1 = explode("(", $clean_name_2[1]); $clean_name = explode(")</name>", $clean_name_1[1]); $clean_user = explode(" {", $clean_name_2[1]); $clean_lower_user = strtolower($clean_user[0]); $clean_uri_1 = explode("<uri>", $entry_close[0]); $clean_uri = explode("</uri>", $clean_uri_1[1]); $clean_time_1 = explode("<published>", $entry_close[0]); $clean_time = explode("</published>", $clean_time_1[1]); $unix_time = strtotime($clean_time[0]); $pretty_time = relativeTime($unix_time); $super_clean_name_2 = $clean_name[1]; $super_clean_name_1 = explode (".com/", $super_clean_name_2); $super_clean_name = $super_clean_name_1[1]; echo $prefix_sub; if ($show >= 1) { echo "<a href=\"http://www.twitter.com/" . $super_clean_name . "\">" . $super_clean_name . "</a> " . $wedge; } echo $clean_content[0]; echo $suffix_sub; } } echo $prefix; parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub); echo $suffix; ?> <body> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/180473-solved-has-to-be-explode/ Share on other sites More sharing options...
Alex Posted November 5, 2009 Share Posted November 5, 2009 I'm not really familiar with the structure, and it's hard to decipher someone else's code but the easiest solution would be just to use strip_tags. $super_clean_name = strip_tags($super_clean_name_1[1]); Quote Link to comment https://forums.phpfreaks.com/topic/180473-solved-has-to-be-explode/#findComment-952082 Share on other sites More sharing options...
steelmanronald06 Posted November 5, 2009 Author Share Posted November 5, 2009 I'm not really familiar with the structure, and it's hard to decipher someone else's code but the easiest solution would be just to use strip_tags. $super_clean_name = strip_tags($super_clean_name_1[1]); Awesome, AlexWD. Like I said, my brain is shutting down. Completely spaced on the php strip_tag() function. Anyone have any ideas on the second problem? I can't figure out why <a href""> tags would be thrown at the end of my domain name. Quote Link to comment https://forums.phpfreaks.com/topic/180473-solved-has-to-be-explode/#findComment-952088 Share on other sites More sharing options...
Alex Posted November 5, 2009 Share Posted November 5, 2009 Whoops, forgot to address your second problem You're gonna want to use echo html_entity_decode(). Ex: echo html_entity_decode($clean_content[0]); Because if you look at their source they use html entities for the quotes inside the a tag. Quote Link to comment https://forums.phpfreaks.com/topic/180473-solved-has-to-be-explode/#findComment-952094 Share on other sites More sharing options...
steelmanronald06 Posted November 5, 2009 Author Share Posted November 5, 2009 Perfect, Alex. Thanks a million. I obviously need to take a step away from the computer. Just spent 5 hours coding Google Maps API into our site, linking it to a geocode library so I can get long/lat, editing all the stupid little buttons and everything. Anyways, thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/180473-solved-has-to-be-explode/#findComment-952102 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.