Case insensitive preg_replace_callback

前端 未结 5 1080
忘了有多久
忘了有多久 2021-01-26 03:48

In the function below, I want to match the keyword case insensitive (should match \"Blue Yoga Mats\" and \"blue yoga mats\")...

However, it currently only matches if the

5条回答
  •  渐次进展
    2021-01-26 04:10

    You can also use T-Regx library:

    replace($post->post_content)->callback('doReplace');
          // ↑ Delimiters are not required 
    

    Also, use of $mykeyword might cause user-input characters to break your pattern. With T-Regx you can use Prepared Patterns and just build your pattern:

     $mykeyword  
        // quoting unsafe characters
    ]);
    $pattern->replace($post->post_content)->callback('doReplace');
    

提交回复
热议问题