3

enter image description hereI am using this function to color all the matches in my search. It works on lowercase words, in Cyrillic script, like "search" but not with "Search".

The function:

public function highlight($text='', $word='')
    {
        if(strlen($text) > 0 && strlen($word) > 0)
        {
            return (str_ireplace($word, "<span class='highlights'><strong>" . $word . "</strong></span>", $text));
        }
        return $text;
    }

I've been thinking about it but I don't know how I should change it, to make it work. Can you give me advice? Thank you in advance!

Decent Dabbler
  • 22,532
  • 8
  • 74
  • 106
Toma Tomov
  • 1,476
  • 19
  • 55
  • i try but your code working properly. Please explain with example. – Jaydeep Mor Jun 22 '17 at 13:05
  • I've added a picture :) Word, that starts with uppercase, can't be colored. – Toma Tomov Jun 22 '17 at 13:39
  • Possible duplicate of [str\_ireplace does not work with non ASCII charecters](https://stackoverflow.com/questions/5221947/str-ireplace-does-not-work-with-non-ascii-charecters) – Decent Dabbler Jun 22 '17 at 13:47
  • Take a look at [this answer](https://stackoverflow.com/a/44626512/4265352) on a similar question. – axiac Jun 22 '17 at 13:58
  • Possible duplicate of [str\_ireplace works as str\_replace](https://stackoverflow.com/questions/44625860/str-ireplace-works-as-str-replace) – axiac Jun 22 '17 at 13:58

0 Answers0