Jump to content

Trouble with file_get_contents


jiggens

Recommended Posts

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";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/148807-trouble-with-file_get_contents/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.