郁闷的新闻内容显示??!!

shuixianzi00 2004-03-31 08:28:02
有转换成HTML特殊字符,以便在数据库中保存,在填加时候,

$title=addslashes($title);
$content=addslashes($content);
$contents=htmlspecialchars($contents);
$content=str_replace("<","<",$content);
$content=str_replace(">",">",$content);
$content=str_replace(chr(13),"<BR>",$content);
$content=str_replace(chr(32)," ",$content);
输出的时候
$title=StripSlashes($row["title"]);
$content=StripSlashes($row["content"]);
$content=nl2br($content);
$content=str_replace("<","<",$content);
$content=str_replace(">",">",$content);
$content=str_replace("<BR>",chr(13),$content);
$content=str_replace(" ",chr(32),$content);
段首空格成了“????”
郁闷!不过我$content=str_replace("??",chr(32),$content);也没有空格,
$content=str_replace("??",“ ”,$content);也不行,空格不是这样表示?
为何不认识?
...全文
63 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2004-04-01
  • 打赏
  • 举报
回复
1、在入库前做html标记转换是没有意义的,因为你读出后还要做逆转换
2、一定要做html标记转换的话,也只需
$content=htmlspecialchars($content);
$content=nl2br($content);
$content=str_replace(chr(32)," ",$content); //注意,一般不做次转换。因为html标记中的空格也被转换了,如不做逆转换就一塌糊涂了
3、做了html标记转换后内容一般用于直接输出html标记
4、$content=str_replace(" ",chr(32),$content);不会出现你说的现象
5、虽然你的代码做了不少无用功,次序上也不竟合理。但执行结果还是正确的
6、你的代码似应改写成
入库前做
if(! get_magic_quotes_gpc())
$content=addslashes($content);
输出的时候
$content=$row["content"];
if(get_magic_quotes_runtime())
$content = StripSlashes($content);
$content=nl2br($content);
$content = preg_replace("/\n +/","\n    ",$content);
52juanjuan 2004-04-01
  • 打赏
  • 举报
回复
function doCheckChar($value)
{
$tt = stripslashes(stripslashes(stripslashes($value)));
$tt = addslashes($tt);
return $tt;
}

在存取之前进行调用就可以满足你的要求了
xieyj 2004-03-31
  • 打赏
  • 举报
回复
$content=str_replace("??",chr(10),$content);

21,893

社区成员

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

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