Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div><span style="background: #f00">My hair cut so cool!</span></div>
- 0:
- 1: $term = 'cool';
- 2: ob_start();
- 3:
- 10: foreach($items as $item) {
- 11: // echoing results here
- 12: echo '<div>' . $item->text . '</div>';
- 13: }
- 30: $content = ob_get_contents();
- 31: ob_clean() ;
- 32:
- 33: $pattern = "/(?<!<[^>])($term)/i";
- 34: $replace = "<span style="background: #f00">$1</span>";
- 35: echo preg_replace($pattern, $replace, $content);
- 36:
- $pattern = "/[^<>]*$term[^<>]*/i";
- $replace = "<span style="background: #f00">$0</span>";
Add Comment
Please, Sign In to add comment