highlighting search results in php/mysql(突出显示 php/mysql 中的搜索结果)
问题描述
如何使用 php 突出显示来自 mysql 查询的搜索结果?
这是我的[修改]代码:
您可以使用 preg_replace();,当它在您的文本中找到匹配项时,您可以在匹配的单词周围放置一个带有突出显示类的 div.然后,您将向高亮类添加背景颜色和边框以使其脱颖而出
preg_replace 需要 3 个参数;
- 第一个是您要查找的内容
- 第二个是应该改成什么
- 他应该搜索和替换的文本字符串
例如
我只为阿拉伯语做了这件事,但您可能也需要为 cQuotes、vAuthor 和 vReference 这样做.
how do i highlight search results from mysql query using php?
this is my [modified] code:
you could use preg_replace();, when it finds a match in your text you could place a div with a class of highlight around the matching word. You would then add a background color and border to the highlight class to make it stand out
preg_replace expect 3 parameters;
- the first one is what you are looking for
- second one is what should it be changed to
- The string of text he should search and replace from
so for example
I only did it for arabic but you might need to do that for cQuotes, vAuthor and vReference as well.
这篇关于突出显示 php/mysql 中的搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!