Checking for an error from file_get_contents() : file_get_contents « File Directory « PHP






Checking for an error from file_get_contents()

 
$page = file_get_contents('page-template.html');

if ($page === false) {

   print "Couldn't load template: $php_errormsg";
} else {
   // ... process template here
}

//page-template.html
<html>
<head><title>{page_title}</title></head>
<body bgcolor="{color}">

<h1>Hello, {name}</h1>

</body>
</html>
  
  








Related examples in the same category

1.Check net speed by loading a file
2.Fetching a URL with file_get_contents()
3.Reading a file into a string
4.file_get_contents.php
5.file_put_contents( ) writes to a file with the equivalent of fopen( ), fwrite( ), and fclose( ) all in one function, just like file_get_contents( ).
6.Use file_get_contents with a URL
7.Retrieving a protected page
8.Retrieving a remote page with file_get_contents()