Home > Blockchain >  preg_match(): Unknown modifier ')
preg_match(): Unknown modifier ')

Time:01-12

getting the error ErrorException: preg_match(): Unknown modifier ')' in file C:\wamp\www\abcd\app\Rules\Htmlstring.php on line 35 for below code.

$rules = ['cartTemplate'=>['required',new Htmlstring],];

class Htmlstring implements Rule
{
  public function passes($attribute, $value)
    {
      return preg_match('/<(/)?(body|html|head|p|b|strong|a|i|span|div)*>/',$value);
    }
}

CodePudding user response:

You have an unescaped slash inside your regex:

/<(/)?(body|html|head|p|b|strong|a|i|span|div)*>/
   ^
   |
This one

You can change it this way:

return preg_match('/<(\/)?(body|html|head|p|b|strong|a|i|span|div)*>/', $value);

Now it works.

  •  Tags:  
  • Related