case insensitive highlighting in php

前端 未结 1 595
长发绾君心
长发绾君心 2021-01-14 13:28

i\'m using this function to highlight the results from mysql query:

 function highlightWords($string, $word)
 {

        $string = str_replace($word, \"

        
1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-14 14:12

    Use str_ireplace() instead.

    EDIT: Here is regexp version that keeps original case:

    $string = preg_replace("/".preg_quote($word, "/")."/i", "$0", $string);
    

    0 讨论(0)
提交回复
热议问题