str_replace("数组","<font color='red'>数组</font>",$str);
这样还会有乱吗?

解决方案 »

  1.   

    单字节和双字节公用的时候,使用str_replace时候会出现乱码现象。
      

  2.   

    可以加载php_mbstring.dll模块,使用宽字节函数。
      

  3.   

    到那里可以找到这个模块php_mbstring.dll,如何加载?谢谢!
      

  4.   

    function chn_str_replace($needle,$string,$haystack) {
        $l = strlen($haystack);
        $l2 = strlen($needle);
        $l3 = strlen($string);
        $news = "";
        $skip = 0;
        $a = 0;
        while ($a < $l) {
            $ch = substr($haystack,$a,1);
            $ch2 = substr($haystack,$a+1,1);
            if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
                if (substr($haystack,$a,$l2) == $needle) {
                    $news .= $string;
                    $a += $l2;
                } else {
                    $news .= $ch.$ch2;
                    $a += 2;
                }
            } else {
                if (substr($haystack,$a,$l2) == $needle) {
                    $news .= $string;
                    $a += $l2;
                } else {
                    $news .= $ch;
                    $a++;
                }
            } // END IF
        } // END WHILE
        return $news;
    }