为什么字符替换会出现乱马?

xcgh 2002-10-23 06:39:10
我用str_replace(数组,"<font color='red'>".数组."</font>",$str)完成字符替换,为什么会有乱马?为什么?
...全文
34 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hucool 2002-11-12
  • 打赏
  • 举报
回复
要用单字节就用单字节,
要用双字节就用双字节。
不要单、双字节混着用,
还有全角和半角了!

上面的这些都是一些细节问题了!要注意的!嘿嘿
icewolf_li 2002-11-12
  • 打赏
  • 举报
回复
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;
}
xcgh 2002-11-12
  • 打赏
  • 举报
回复
如何解决我的问题??如分不够我可以再加。
uGain 2002-11-12
  • 打赏
  • 举报
回复
我还以为小茜也在呢
:P
xcgh 2002-11-12
  • 打赏
  • 举报
回复
到那里可以找到这个模块php_mbstring.dll,如何加载?谢谢!
goodname 2002-10-24
  • 打赏
  • 举报
回复
可以加载php_mbstring.dll模块,使用宽字节函数。
xcgh 2002-10-24
  • 打赏
  • 举报
回复
拜托如何解决,谢谢!
tttk 2002-10-24
  • 打赏
  • 举报
回复
单字节和双字节公用的时候,使用str_replace时候会出现乱码现象。
xcgh 2002-10-24
  • 打赏
  • 举报
回复
是没乱马了,但不替换了!
可乐加水 2002-10-23
  • 打赏
  • 举报
回复
str_replace("数组","<font color='red'>数组</font>",$str);
这样还会有乱吗?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧