哈哈 严重关注居然用mb_ereg_replace都乱码!

解决方案 »

  1.   

    1、不要用正则表达式去匹配单个汉字
    2、高版本php的mb_ereg_replace一样会匹配错误,应该是bug。该死的日本鬼子建议拆分成数组,处理后再连接起来
      

  2.   

    这样就行了!<?php
    $str = "我等这么久了,连一个内测号都没有!我看我还是乖乖玩剑侠一吧!剑侠2是掉我们的胃口哼~~讨厌死它了。";function mb_replace($pattern, $replacement, $string, $sourceEncoding)
    {
    $string = mb_convert_encoding($string, "utf-8", $sourceEncoding);
    $pattern = mb_convert_encoding($pattern, "utf-8", $sourceEncoding);
    $replacement = mb_convert_encoding($replacement, "utf-8", $sourceEncoding);
    $string = mb_ereg_replace($pattern, $replacement, $string);
    return mb_convert_encoding($string, $sourceEncoding, "utf-8");
    }echo mb_replace("(日)", "[\\1]", $str, "gb2312");  //其中的"gb2312"与你网页的编码对应
    ?>