How to read the contents of URL into a string in PHP

1 Answer

0 votes
function file_get_contents($fn) 
{
   set_error_handler
   (
     function($severity, $message, $file, $line) 
     { 
       throw new ErrorException($message, $severity, $severity, $file, $line); 
     }
   );
        
   try
   {
       unset($content);
       $content = file_get_contents($fn, true);
   }
   catch (Exception $e)
   {
      echo 'Error exception: ',  $e->getMessage(), "\n";
      return "";
   }
   return $content;
}

$html = file_get_contents($url);
echo $html;


answered Jun 7, 2014 by avibootz
edited Jun 7, 2014 by avibootz

Related questions

2 answers 245 views
1 answer 251 views
2 answers 367 views
1 answer 276 views
2 answers 181 views
...