How to highlight keywords in search results in php

    You can use the below code with the css to highlight keywords in the search results
    Css Styles:
    <style type="text/css">
    .search_highlight {
      background-color:#ffffcc;
    }

    PHP Code to highlight search results
    <?php
    $keywords
    = <SEARCH KEYWORD>; //Keyword to highlight.
    $searchresults = <RETURNED STRING>; //Result of search.
    preg_replace("|($keywords)|Ui", "<span class='search_highlight'>$1</span>", $searchresults);
    ?>
    5
    Average: 5 (1 vote)