改成
<?
$name="心只有你";
$word="心";
$f1="<font color=\"#6963E0\">";
$f2="</font>";
$name=str_replace($word,$f1.$word.$f2,$name);
echo"<td width=\"270\" height=\"20\" valign=\"middle\">$name</td>";
?>

解决方案 »

  1.   

    youbest(冲天飞豹)  首先谢谢你的回答,但我试了一下,问题依然存在,不知这个和php 的配置有没有关系呢?
    ereg_replace和str_replace这两个函数都用过了效果依然。up
      

  2.   

    ‘有’的后半个字节+‘你’的前半个字节=‘心’
    PHP的常规表达式和字符串函数都是这样,可以把问题提交到客户端通过JavaScript来处理就没有问题了。
      

  3.   

    正如楼上所说的那样!
    如果你可以更改服务器设置的话,那么加载一个模块:php_mbstring.dll,然后使用mb_ereg_replace代替ereg_replace即可。也可以通过客户端JavaScript处理,如:
    <script language="Javascript">
    <!--
    function test(name){
    var f1 = '<font color="red">';
    var f2 = '</font>';
    return name.replace(/(心)/, f1+"$1"+f2);
    }
    document.write(test("心只有你"));
    -->
    </script>
      

  4.   

    谢谢回复!
    我在php.ini里面加上了这一句;extension=php_mbstring.dll一旦用到mb_ereg_replace它就出现没有定义的提示。
    Call to undefined function: mb_ereg_replace()不知我的配置出了什么问题呢?
      

  5.   

    应该是与php.ini的配置没有关系!
    eregi_replace()================================================================================<?
    $name="心只有你";
    $word="<font color='#6963E0'>心</font>";
    $name=ereg_replace("$word","$word",$name);
    echo"<td width='270' height='20' valign='middle'>$name</td>";
    ?>
      

  6.   

    发错了,改如此:
    <?
    $name="心只有你";
    $word="心";
    $worde="<font color='#6963E0'>心</font>";
    $name=ereg_replace("$word","$worde",$name);
    echo"<td width='270' height='20' valign='middle'>$name</td>";
    ?>
      

  7.   

    <?
    $name="心只有你";
    $word="心";
    $worde="<font color='#6963E0'>心</font>";
    $name=ereg_replace("$word","$worde",$name);
    echo"<td width='270' height='20' valign='middle'>$name</td>";
    ?>
    这个没错!
      

  8.   

    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;
    }
    替换函数
      

  9.   

    多谢大家的回复,特别谢谢xcgh(晓刚) 的那段程序,回题得到了解决,但不知还有没有另外的问题发生。
    还有,“加载一个模块:php_mbstring.dll”,不知这应该怎么来加载呢?
      

  10.   

    在php.ini里面加上了这一句extension=php_mbstring.dll看清楚,前面没有分号的,然后重新启动服务器程序
      

  11.   

    +++++++++++++++++++++++++++++++++++++++++++++++++++
    不是吧,一个字符串替换真的要用那么长的代码吗?         +
                                                      +
    人家PHP 已经有了ereg_replace();                    +
                                                      +
    你还自己再搞一个出来!晕死                           +
    ++++++++++++++++++++++++++++++++++++++++++++++++++++
    用自己的,精神值得学习第二个在php.ini中加上楼上那么一句之后,如不能用,请检查extension_dir位置
      

  12.   

    别晕,我就是用了那个ereg_replace(),出现了一些问题,再次谢谢xcgh(晓刚)的程序.那个php.ini和extension_dir的位置我都检查过了,可是一用到mb_ereg_replace时,还是提示没有定义。
    不知还有可能是哪个环节出错呢?
      

  13.   

    建议你直接复盖掉你的PHP.iniPHP.INI全文如下!http://www.obird.com/obird/words_view.php?id=46