Page 1 of 1
redirect warning message to string variable
Posted: Fri Jul 03, 2009 6:47 am
by area5one
Hi guys,
I have
Output:
Warning: rmdir(non_existent_dir) [function.rmdir]: No such file or directory in C:\wwwroot\test\index.php on line 59
Any way of getting that string into a variable?
Re: redirect warning message to string variable
Posted: Fri Jul 03, 2009 7:24 am
by Eric!
You can check to see if it is a directory or not and use error handling.
Code: Select all
<?php
if (!is_dir('examples')) {
echo 'Does not exist';
}
else {
if (rmdir('examples')==0) echo 'Failed to remove directory';
else echo 'Directory removed.';
}
?>
Edit: I see that you can from next post. You have to set a callback function to process the error and then you should probably restore the handler unless you want to keep your function as the default way to show errors/warnings.
Re: redirect warning message to string variable
Posted: Fri Jul 03, 2009 7:42 am
by VladSun
Re: redirect warning message to string variable
Posted: Fri Jul 03, 2009 8:32 am
by area5one
Thanks for the link VladSun
Here is an example of printing the error message in a different colour
Code: Select all
function myErrorHandler($errno, $errstr, $errfile, $errline)
{ echo "<span style='color: red'>".$errstr."</span>";
}
set_error_handler("myErrorHandler");
rmdir("non_existent_dir");