PHP:引用较大文本中的搜索结果片段
假设我有一大块文本。我想要一个 PHP 例程或函数来引用或总结给定关键字的文本。有点像 Google 的做法,显示它找到的页面中的一些示例引用。
例如
大文本:
Lorem ipsum dolor sat amet,nam et magna ac vitae a。自由人多内克 前庭疼痛、永远生命、食欲不振 梅图斯SEM. Mi vitae et elit, risus ultrices, ut justo est aenean ultrices feugiat porttitor,vitae lectus。 Posuere tempus, eleifend lacinia ac eros nam consectetuer etiam。 Viverra est arcu nulla,在 velit ipsum rutrum laoreet imperdiet, a dolor nihil nunc non facilisi elit,id sed dui nobis quis,dignissim curabitur。弓形舌苔 Rhoncus rerum elit、amet vitae、ipsum nam volutpat、felis in sed porta ut nulla。 Risus neque aliquet, laoreet convallis dolor mollis。
搜索查询:
关键字:justo
要显示的字数:15
结果:
Mi vitae et elit, risus ultrices, ut justo est aenean ultrices feugiat 搬运工...
是否有标准或常用的例程来执行此操作?
Let's say I have a large block of text. I want a PHP routine or function to quote or summarise that text given a keyword. A bit like Google does, showing some sample quotes from the pages it finds.
eg
Large Text:
Lorem ipsum dolor sit amet, nam et magna ac vitae a. Donec libero
vestibulum dolor dapibus, etiam semper vitae, vel luctus nisl dui
metus sem. Mi vitae et elit, risus ultrices, ut justo est aenean
ultrices feugiat porttitor, vitae lectus. Posuere tempus, eleifend
lacinia ac eros nam consectetuer etiam. Viverra est arcu nulla, in
velit ipsum rutrum laoreet imperdiet, a dolor nihil nunc non facilisi
elit, id sed dui nobis quis, dignissim curabitur. Eget ligula arcu
rhoncus rerum elit, amet vitae, ipsum nam volutpat, felis in sed porta
ut nulla. Risus neque aliquet, laoreet convallis dolor mollis.
Search Query:
Keyword: justo
Words To Show: 15
Result:
Mi vitae et elit, risus ultrices, ut justo est aenean ultrices feugiat
porttitor...
Are there standard or commonly used routines for doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想拥有全功能的全文搜索功能,我会使用 Sphinx Search 这样的搜索服务器。设置起来并不太困难,并且提供非常快速的搜索能力。此外,它还可以根据搜索词为您提供上下文相关的文本片段。
I would use a search server like Sphinx Search if you want to have a full-featured full text search capability. It is not too difficult to setup and provides very fast searching capability. In addition, it can give you context-sensitive snippets of your text based on search terms.