LoginSignup
0

More than 1 year has passed since last update.

【Laravel・PHP】preg_match(): Unknown modifier '�' のエラー

Posted at

状況

正規表現を用いて、文字の検索をかけたいのでpreg_matchを使ったところタイトルのエラーが発生。

コード

$target = '/' . $request->name . '/';
$names = $collection->filter(function($value) use ($target){
   return preg_match($value['name'], $target);
});

原因

preg_matchの第一引数と第二引数を逆に記述したことによるエラー。
本来は第一引数に正規表現、第二引数に元データを記述しなくてはならない。

return preg_match($target, $value['name']);

とっても単純なエラーでした。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0