Highlight function keywords in search results using php

Oct-23-2014 in PHP No comments

You are design the search page? you want to highlight the search keywords in the text or search results when visitors search on your website? we will give you a php function to do that easy!

highlight keywords search results

There are three steps: The first is the search keyword, and then display the content, and ultimately results highlight them on the page result.

To highlight the search keywords in the text we use CSS class putting a span tag with class “highlight” around the keyword. For example,

Css Styles:

 

Here is only be a examples you can modify your css class to choose colors to suit the overall design of your website.

PHP Highlight function keywords Code

 

 

This code will search the string containing keywords to search and then replace the original string with new markup string then display on result page by adding span tag with css style attributes is “highlight”.

How to use function?

We need to input two parameters to the function is: keywords and content string.

 

 

No Responses

Add Your Comment