博客帖子预览显示

时间:2011-03-18 03:53:05

标签: php

    if (strlen($body) > 2000)
                    {
                        $body = substr($body, 0, 2000);
                        $body .= '...<a href="/blogpost/' . $id . '/' . urlencode($title) .'">Read More</a>

';
                }

所以我说<font size="5">切断它时,就像“And he was like<font...Read More”一样。它在屏幕上显示单词<font供最终用户阅读,因为它没有机会关闭,因为它被截断了。有没有修复或解决这个问题?它有点烦人。

2 个答案:

答案 0 :(得分:1)

截取缩写视图的HTML时,我建议首先抛出strip_tags,通常你不需要在缩写内容上格式化/链接,imo。

$plainBody=strip_tags($body);
$abrvBody=strlen($plainBody)>2000?susbtr($plainBody,0,2000):$plainBody;

如果您必须保留格式/链接,则可以随时使用preg_replace

清理切碎的文字
$cleanAbrvBody=preg_replace('/<[^>]+$/','',susbtr($body,0,2000));

虽然您最终可能会使用未关闭的标签。

答案 1 :(得分:0)

使用:

strip_tags()

......这会有所帮助。

相关问题