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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.