Highlight matched words in a search

This tutorial will show you how to highlight words from a search.

To learn how to search with php see Searching with PHP and MySQL beyond LIKE

First here is the function that will detect which words if any to highlight. The function expects 2 parameters
first the content and the words to search against.

A foreach loop is performed incase there is more then one search term, inside the loop a str_ireplace to replace each word from
search and wrap it in a span with a class to style the work with css then return the modified content.

Usage example

Search Example