帮忙分析如下代码中,关于 str_replace() 函数的替换问题!

下面这个在 文件名为 function.php里
<?php
function unhtml($content)
{
$content=str_replace("&","& a m p;",$content);
$content=str_replace("<","& l t;",$content);
$content=str_replace(">","& g t;",$content);
$content=str_replace(" ","&n b s p;",$content);
$content=str_replace(chr(13),"<br>",$content);
$content=str_replace("\\","\\\\",$content);
$content=str_replace("台什么","不文明用语",$content);
$content=str_replace(chr(34),""",$content);
$content=str_replace("[emt]","<img src=images/xyq/",$content);
$content=str_replace("[/emt]",".gif/>",$content);
return $content;
}
?>

下面在这个SHOW.php里
从数据库里读取1段文字(值给$content)
导入函数
<?php include_once("function.php");
echo unhtml($content);
?>
结果是 该屏蔽的没屏蔽 该替换的没换
比如
台什么[emt]1[/emt]
换成
不文明用语<img src=images/xyq/1.gif/>
才对嘛

HUWWW
浏览 161回答 1
1回答

白衣非少年

程序里面下面这一句有语法错误:$content=str_replace(chr(34),""",$content);可以修改为:$content=str_replace(chr(34),'"'",$content);或者取消,好像没有什么本质意义。程序前面几行替换HTML代码的,代码中间不能有空格,你写错了。我修改后,完整的测试程序如下,测试通过,没有问题,能够替换:<?phpfunction unhtml($content){$content=str_replace("&","&amp;",$content);$content=str_replace("<","&lt;",$content);$content=str_replace(">","&gt;",$content);$content=str_replace(" ","&nbsp;",$content);$content=str_replace(chr(13),"<br>",$content);$content=str_replace("\\","\\\\",$content);$content=str_replace("台什么","不文明用语",$content);$content=str_replace("[emt]","<img src=images/xyq/",$content);$content=str_replace("[/emt]",".gif/>",$content);return $content;}$str='台什么[emt]1[/emt]';echo unhtml($str);?>程序运行过程如下:E:\ygb>php a.php不文明用语<img src=images/xyq/1.gif/>&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP