Support » Plugin: Better Search » Highlighted search word all lowercase

  • Hello Ajay & everybody,

    Is there a fix for turning all search words in lowercase? If visitors search for names I would like to keep the first letter a capital. The culprit is in (my) better-search.php:

    $sr = get_query_var('s');
    $keys = explode(" ",$sr);
    $excerpt = preg_replace('/('.implode('|', $keys) .')/iu', '<strong>'.$sr.'</strong>', $excerpt);

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Ajay


    How about using something like

    $sr = strtolower( get_query_var('s') );

    Sorry for not being clear Ajay. I meant that the highlighted words in the search results are all in lowercase, e.g. “John Doe” turned into “john doe”, but I want to keep the capitals. If there is a fix for that.

    Plugin Author Ajay


    I’m no expert on regex, but what if you omit the i in :
    /('.implode('|', $keys) .')/iu

    But, this might not completely solve your problem because the way I understand it, the search terms are very dependent on that of the user’s search.

    Another option could be to capture the matches wherever there is a search term using preg_match_all and use those to highlight the words int he excerpt

    Regex is a nightmare to me… perhaps someone else can help?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Highlighted search word all lowercase’ is closed to new replies.