Highlighting certain words with some regex

(Or looking for highlighting PHP code itself?)

Text:
Highlight word:

Output in htmlspecialchars()


Normal output

Code

$output = preg_replace(
  "/(>|^)([^<]+)(?=<|$)/esx",
  "'\\1' . str_replace('" . $keyword . "', '<b>" . $keyword . "</b>', '\\2')",
  $input
);