- function highlighter_text($text, $words)
- {
- $split_words = explode( " " , $words );
- foreach($split_words as $word)
- {
- $color = "#4285F4";
- $text = preg_replace("|($word)|Ui" ,
- "" , $text );
- }
- return $text;
- }
复制代码
用法:
- $string = "I like chocolates and I like apples";
- $words = "apple";
- echo highlighter_text($string ,$words);
- ?>
复制代码
|