note 35124 added to function.preg-match
| From: | plenque at hotmail dot com | Date: | Wed, 20 Aug 2003 14:19:54 +0000 |
| Subject: | note 35124 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-54765@lists.php.net to get a copy of this message | ||
I wrote a function that checks if a given regular expression is valid. I think some of you might
find it useful. It changes the error_handler and restores it, I didn't find any other way to do
it.
Function IsRegExp ($sREGEXP)
{
$sPREVIOUSHANDLER = Set_Error_Handler ("TrapError");
Preg_Match ($sREGEXP, "");
Restore_Error_Handler ($sPREVIOUSHANDLER);
Return !TrapError ();
}
Function TrapError ()
{
Static $iERRORES;
If (!Func_Num_Args ())
{
$iRETORNO = $iERRORES;
$iERRORES = 0;
Return $iRETORNO;
}
Else
{
$iERRORES++;
}
}
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35124
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35124&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35124&report=yes