Question

\\    $DigitalSignature have full name value passed
$SignatureMatch =  '/' . strtolower( $NameFirst . ' ' . $NameLast ) . '$/';
if( true == preg_match( $SignatureMatch, strtolower( $DigitalSignature ) ) )
{
    $boolIsValid = true;
}

I am having this code for exact matching first name and last name match with digital signature. But this gives error reported me in error log on production(live).

preg_match(): Unknown modifier 'b'

I am unable to reproduce this error. How can I get this error firstly. And how to resolve this error for exact matching.

I have seen many questions on SO but not getting when will get this error. And how do I resolve that. Some of questions out of many I have saw are -

  1. Warning: preg_match() [function.preg-match]: Unknown modifier
  2. Unknown modifier in preg_match() statement
  3. Warning: preg_match() [function.preg-match]: Unknown modifier
  4. Unknown modifier 'l' error
  5. Unknown modifier 'g' PHP regex error
  6. Unknown modifier '/' in ...? what is it?
  7. preg_match() Unknown modifier '[' help
  8. Warning: preg_match() [function.preg-match]: Unknown modifier 'v'
  9. PHP Preg_match match exact word
  10. Unknown modifier 'v' when using preg_match() expression in regex
  11. preg_match(); - Unknown modifier '+'
  12. preg_match error Unknown modifier '{'
  13. Unknown modifier '(' when using preg_match() with a REGEX expression
Was it helpful?

Solution

If the first name or last name contains a /, your regex will look something like:

/john/doe$/

To preg_match, this looks like the regex is /john/, with the trailing doe$/ being the modifiers. Those are of course invalid modifiers. You need to escape the regex delimiters (/) inside the regex itself using preg_quote.

OTHER TIPS

One of the strings you're inputting ($NameFirst or $NameLast) contains a /. Use a different delimiter or escape it in the strings.

Also, if you're only checking if a substring is inside a different string, don't use preg_match, use stripos() as it will be much faster.

if (stripos($DigitalSignature ,"$NameFirst $NameLast")) { /* It exists! */ }

$NameFirst or $NameLast may contain a slash /.

You should replace this

$SignatureMatch =  '/' . strtolower( $NameFirst . ' ' . $NameLast ) . '$/';

By this :

$SignatureMatch =  '/' . preg_quote(strtolower( $NameFirst . ' ' . $NameLast ), '/') . '$/';

You should not be using a regular expression in this case because you are not using any pattern matching. If you just want to find one string inside of another, then use the strpos or strrpos functions: http://php.net/manual/en/function.strpos.php

If it's important that the name be found at the end of the signature, then it's even easier: Take a substring from $signature that is that many characters long from the end.

$fullname = strtolower( "$NameFirst $NameLast" );
$len = strlen($fullname);
$possible_name = substr( $fullname, -$len, $len );
$boolIsValid = ( $possible_name == $fullname );

If you were using T-Regx, the delimiters would be added for you automatically:

$SignatureMatch =  strtolower($NameFirst . ' ' . $NameLast) . '$';

if (pattern($SignatureMatch, 'i')->matches($DigitalSignature))
{
    $boolIsValid = true;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top