highlighting search results in php/mysql

前端 未结 2 681
南方客
南方客 2020-12-07 03:44

how do i highlight search results from mysql query using php?

this is my [modified] code:

$search_result = \"\";

$search_result = $         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 04:22

    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;

    1. the first one is what you are looking for
    2. second one is what should it be changed to
    3. The string of text he should search and replace from

    so for example

    ".$search_result."", h($row['cArabic'])); ?>
    Search Results

    I only did it for arabic but you might need to do that for cQuotes, vAuthor and vReference as well.

提交回复
热议问题