使用dedecms网站程序时.发表文章时出现"把数据保存到数据库主表 `dede_archives` 时出错,
出错原因是dede自动截取文章简介产生乱码引起保存到数据库出错。
解决方法是替换掉dede的一个函数(SpHtml2Text):
此函数在下面文件 第四行:
include\inc\inc_fun_funString.php
原型是:
function SpHtml2Text($str){
$str = preg_replace("/<sty(.*)\\/style>|<scr(.*)\\/script>|<!--(.*)-->/isU","",$str);
$alltext = "";
$start = 1;
for($i=0;$i<strlen($str);$i++){
if($start==0 && $str[$i]==">") $start = 1;
else if($start==1){
if($str[$i]=="<"){ $start = 0; $alltext .= " "; }
else if(ord($str[$i])>31) $alltext .= $str[$i];
}
}
$alltext = str_replace(" "," ",$alltext);
$alltext = preg_replace("/&([^;&]*)(;|&)/","",$alltext);
$alltext = preg_replace("/[ ]+/s"," ",$alltext);
return $alltext;
}
其作用是去掉所有htm标记。
俺替换成下面的函数:
function SpHtml2Text($str){
$alltext = str_replace(" ","",$str);
$alltext=strip_tags(trim($alltext));//haha123_0 去掉所有htm标记
return $alltext;
}
