0

在使用 smarty 模板的文章网站上,我需要截断主要内容以创建预告片。我可以按字符截断,但第一段的长度从文章到文章是完全未知的。我想要更聪明的东西,只显示第一段:

内容:

This is my first paragraph and I want to display this and only this.

This the rest of the content and it is very long with a lot of words...

预告片:

This is my first paragraph and I want to display this and only this.
4

1 回答 1

0

那么此时要截断 wiki 语法或 html 的文本?如果是 wiki,您应该能够使用strposphp 函数搜索 \n\n (如果它不是允许的函数之一,请将其添加到安全控制面板中的 smarty 函数中)。然后,您可以substr对文本执行功能并在其后添加“...”或其他任何内容。如果它是 html,那么 apreg_replace可能是最好的方法 - 比如

{preg_replace('/^.*?<\/p>/mis','$1"',$content)}...

...可能只是工作(未经测试,对不起;)HTH

于 2017-10-10T04:33:30.180 回答