您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

字符转义有关问题

2024/6/27 20:06:29发布28次查看
字符转义问题
比如这样的字符串
[td]for god\'s sake! [/td]
我把单引号转义了,存进数据库。
显示文章的时候,发现文章都带有转义斜杠了。
而不转义直接保存进数据库,有些时候插入数据库会错误。这该怎么办呀?
//转换某些特殊字符
function format_html($str){
$str = str_replace('“', '“',$str);
$str = str_replace('”', '”',$str);
$str = str_replace('·', '·',$str);
$str = str_replace('‘', '‘',$str);
$str = str_replace('’', '’',$str);
$str = str_replace('…', '…', $str);
$str = str_replace('—;', '―', $str);
return $str;
}
另外,php有内置函数的作用能达到我上面那个函数一样的效果吗?因为上面转的也不全完整。
------解决方案--------------------
php code$str = for god's sake!;//入库时...insert into tb ... col = '.addslashes($str).'...//输出时echo htmlspecialchars($str);
------解决方案--------------------
mysql_real_escape_string
------解决方案--------------------

探讨
mysql_real_escape_string
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product