Andrei Popovici wrote:

I have a script which reads his configuration from an ini file. For reading
that file I use the parse_ini function. When the ini is written incorectly
the php displays a message that he has encountered a parse error in that
ini. How can I catch that error and display a message of my own?

Had to think about this one for a bit... :)


If you know the contents of the ini file, you could always count() the resulting array to determine if all of the values were read correctly. The "error" that's displayed is just a warning, so a proper error_reporting() level would take care of the message not being displayed.

Or, as an alternate solution, you can use output buffering to capture the error.

<?php
$old_error_level = error_reporting(E_ALL);

ob_start();
$array = parse_ini_file('file.ini');
$response = ob_get_contents();
ob_end_clean();

if(strlen($r)>0)
{ echo "error while parsing file"; }
else
{ echo "no error"; }

?>

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to