How can the highlight_string() function in PHP handle non-breaking spaces and black question marks?

The highlight_string() function in PHP may not handle non-breaking spaces and black question marks properly because it may not recognize these characters as part of the string to be highlighted. To solve this issue, we can use the htmlentities() function to convert these special characters into their HTML entities before passing the string to the highlight_string() function.

$string = "This is a string with non-breaking space: hello and a black question mark: �";
$highlighted_string = highlight_string(htmlentities($string), true);

echo $highlighted_string;