If you look in the PHP manual, it goes into a bit of detail about interceptong, and redirecting error messages. If you want a very simple error intercept, most all PHP commands allow you to turn off the error reporting for a particuliar function by using the "@" symbol. The error is still tripped, but the script will try to continue execution, and no message is printed out.
ie.
$FileArr = @file("path/to/file");
If an error occurrs, it will not be displayed.
You can setup some constants to hold your error messages.
define("READ_ERROR",0);
define("WRITE_ERROR",1);
Function error_msg($err,$str=''){
switch($err){
case 0:
echo "An error has occurred while trying to read the file $str";
break;
case 1:
echo "An error has occurred while trying to write to the file $str";
break;
default:
echo "An unknown error has occurred";
}
}
Now we can catch the error like this
if ($FileArr == @file("path/to/file/to/read") || die(error_msg(READ_ERROR,"path/to/file/to/read"))){
do something here;3
}
or, if you do not wish to stop the script execution
if ($FileArr == @file("path/to/file/to/read")){
do something here;
}else{
error_msg(READ_ERROR,"path/to/file/to/read");
}
Or you can simply redirect the error messages to a log file.
The PHP manual explains how to do this, but for a very simple error catching routines, this works nicely.