> 3) Include and execute capturing critical errors:
>
> $hf = fopen($incfile, 'r');
> if ($hf) {
> $buffer = fread($hf, filesize($incfile));
> fclose($hf);
> }
> if ($buffer) {
> global $php_errormsg;
> $php_errormsg = null;
> @eval($buffer);
> $err = $php_errormsg;
> }
>
1) Include file not found:
if (file_exists($incfile))
include($incfile);
else
include ($error_html_file);
2) Error in file:
global $php_errormsg;
$php_errormsg = null;
@include($incfile);
$err = $php_errormsg;
if ($err)
echo "The include file $incfile has an error: $err";
The trick is
> I want to display an HTML page if PHP can't load an include
> file or otherwise has an error or just doesn't work.
> How do I do this?
include returns false on failure and here's a hack to
demonstrate. Once you implement your own error
handling, be sure to set error_reporting accordingly
or
if ( !@include ( "myfile.php" ) ) {
// do this if file cannot be included
...code...
...code...
}
Bob Lockie wrote:
I want to display an HTML page if PHP can't load an include file or
otherwise has an error or just doesn't work.
How do I do this?
--
PHP General Mailing List (h
Quoting Bob Lockie <[EMAIL PROTECTED]>:
###
### I want to display an HTML page if PHP can't load an include file or
### otherwise has an error or just doesn't work.
### How do I do this?
###
if (!$variable){print('your html stuff');}
Kinda basic, but it might help.
Cheers!
VW
###
### --
Hi Bob,
> I want to display an HTML page if PHP can't load an
> include file or otherwise has an error or just doesn't work.
> How do I do this?
Not sure you can, especially not for the "just doesn't work" scenario.
FWIW, you can test for the existence of a file before including it:
if (file_e
6 matches
Mail list logo