mysql中既有html代码,又有中文,php怎么只取出数据库中的中文?

数据库中有html样式的,怎么样只取文字?
2025-12-16 08:53:42
推荐回答(3个)
回答1:

给你两个思路
1,读取出来后,删除所有的html代码
function html2txt($document){
$search = array('@]*?>.*?@si', // 去掉脚本
'@]*?>.*?@siU', // 去掉css
'@<[\/\!]*?[^<>]*?>@si', // 去掉html
'@@' // 去掉ddt头部
);
$text = preg_replace($search, '', $document);
return $text;
} 这条函数可以做到
2,采用正则表达式匹配中文
$str = "04aol汉字";
$pattern = "/^(\d{2})([A-Za-z]{3})([".chr(0xa1)."-".chr(0xff)."]+)$/";
if(preg_match($pattern, $str, $tmp))
{
print_r($tmp);
}

回答2:

将html标签过滤掉就好,用Php函数strip_tags().

回答3:

怎么个意思?