Better Search
Highlighted search word all lowercase (5 posts)

  1. Annekee
    Posted 2 years ago #

    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!


  2. Ajay
    Plugin Author

    Posted 2 years ago #

    How about using something like

    $sr = strtolower( get_query_var('s') );
  3. Annekee
    Posted 2 years ago #

    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.

  4. Ajay
    Plugin Author

    Posted 2 years ago #

    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

  5. Annekee
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic