jiggens Posted March 10, 2009 Share Posted March 10, 2009 I am trying to setup hyperlink using get_file_contents for the url http://bloomburg.com/news/breakingnews/ I also want to have it update each time i thought i had it but i keep getting NO DATA its dying on me. <?php // Corys Tempblog_bloomberg.php // THE DATA FEED $home = 'http://www.bloomberg.com/news/breakingnews/'; // GET THE FEED $data = file_get_contents($home); // GET RID OF THE UNWANTED STUFF $xstr1 = '<div class="contentbox">'; $xstr2 = '</div>'; $text = explode($xstr1, $data); $data = $text[1]; $text = explode($xstr2, $data); $data = $text[0]; // FIND FIRST USEFUL INFORMATION $psum = '<p class="summ">'; $pos = strpos($data, $psum); if ($pos === FALSE) die('NO DATA'); $data = substr($data, $pos); // CLEAN UP THE LINKS $data = str_replace('/apps/news', 'http://www.bloomberg.com/apps/news', $data); // USE THE PARAGRAPH TAGS TO BREAK THIS TEXT INTO AN ARRAY $data = str_replace('</p>', '', $data); $data = str_replace('<br>', '', $data); $xstr3 = '<p class="summ">'; $text = explode($xstr3, $data); // ITERATE OVER THE TEXTS (COUNT LIMITED) foreach ($text as $pointer => $data) { if ($pointer > 5) break; echo "<p>"; echo $data; echo "</p>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148807-trouble-with-file_get_contents/ Share on other sites More sharing options...
wildteen88 Posted March 10, 2009 Share Posted March 10, 2009 The link you provided does not load for me. Are you sure you're using the correct address. Can you confirm something is set in $data? Before // FIND FIRST USEFUL INFORMATION Add echo $data; Also you're receiving the NO DATA message because php cannot find <p class="summ"> within the string that is held in the $data variable. If http://www.bloomberg.com doesn't exist/load you cannot expect your script to still function Quote Link to comment https://forums.phpfreaks.com/topic/148807-trouble-with-file_get_contents/#findComment-781435 Share on other sites More sharing options...
jiggens Posted March 10, 2009 Author Share Posted March 10, 2009 http://bloomberg.com does exist. Quote Link to comment https://forums.phpfreaks.com/topic/148807-trouble-with-file_get_contents/#findComment-781459 Share on other sites More sharing options...
Mark Baker Posted March 10, 2009 Share Posted March 10, 2009 Isn't this in breach of the Bloomberg Terms of Service? Quote Link to comment https://forums.phpfreaks.com/topic/148807-trouble-with-file_get_contents/#findComment-781598 Share on other sites More sharing options...
synking Posted March 10, 2009 Share Posted March 10, 2009 There terms say as long as it is not commercial use but the address is /news/breakingnews. i had something similar so i hope it is not breaking the TOS Quote Link to comment https://forums.phpfreaks.com/topic/148807-trouble-with-file_get_contents/#findComment-781608 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.