Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - When does preg_match(): Unknown modifier error occur?

\    $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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...