match whole word only without regex

前端 未结 4 1874
既然无缘
既然无缘 2021-01-26 07:27

Since i cant use preg_match (UTF8 support is somehow broken, it works locally but breaks at production) i want to find another way to match word against blacklist. Problem is, i

4条回答
  •  故里飘歌
    2021-01-26 07:46

    A simple way to use word boundaries with unicode properties:

    preg_match('/(?:^|[^pL\pN_])(badword)(?:[^pL\pN_]|$)/u', $string);
    

    In fact it's much more complicated, have a look at here.

提交回复
热议问题