PHP str_replace() 函数 替换问题!
来源:百度知道 编辑:UC知道 时间:2024/09/20 06:54:08
下面这个在 文件名为 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"
<?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"
程序里面下面这一句有语法错误:
$content=str_replace(chr(34),""",$content);
可以修改为:
$content=str_replace(chr(34),'"'",$content);
或者取消,好像没有什么本质意义。
程序前面几行替换HTML代码的,代码中间不能有空格,你写错了。
我修改后,完整的测试程序如下,测试通过,没有问题,能够替换:
<?php
function unhtml($content)
{
$content=str_replace("&","&",$content);
$content=str_replace("<","<",$content);
$content=str_replace(">",">",$content);
$content=str_replace(" "," ",$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(&