我希望您能为我解决这个问题,问题是我在PHP博客中使用TinyMCE,编辑器运行良好,数据库中的数据正确接收,但是在博客的主页上我只想显示一些我尝试使用substr()函数作为post_content的一部分,而不是全部内容,但由于数据库中的$ row ['post_content']列包含'html标记',因此无法正常工作。请问有什么解决方案可以在首页中仅显示Post_content的几句话?谢谢
这样的东西
function html2txt($text, $Hremove = 1)
{
if ($Hremove == 1) {
//remove H's
$text = preg_replace('~<(h[1-6])(?=[\s>])[^<>]*>([^<]*(?:<(?!/\1)[^<]*)*)</\1>~', '', $text);
} else {
$text = preg_replace('/<\/h(.*?)>/', '. ', $text);
}
//$text = strip_tags($text);
$text = preg_replace('#<a.*?>(.*?)</a>#i', '\1', $text);
$text = preg_replace('/</', ' <', $text);
$text = preg_replace('/>/', '> ', $text);
$text = htmlX_entity_decode(html2txtall($text));
$text = preg_replace('/[\n\r\t]/', ' ', $text);
$text = preg_replace('/ /', ' ', $text);
$text = trim($text, " \t\n\r\0\x0B\xC2\xA0");
return $text;
}
echo substr(trim(html2txt($row['post_content'])), 0, 200);