Preg_Replace and UTF8

后端 未结 3 991
清酒与你
清酒与你 2021-01-05 22:55

I\'m enhancing our video search page to highlight the search term(s) in the results. Because user can enter judas priest and a video has Judas Priest

3条回答
  •  情书的邮戳
    2021-01-05 23:51

    I feel really stupid right about now but the problem wasn't with Preg_* functions at all. I don't know why but I first checked if the given term is even in the string with StriPos and since that function is not multi-byte safe it returned false if the case of the text was not the same as the search term, so the Preg_Replace wasn't even called.

    So the lesson to be learned here is that always use multi-byte versions of functions if you have UTF8 strings.

提交回复
热议问题