Using the array from this answer: https://stackoverflow.com/a/11179875/3578036
$string = 'Some <b>bold</b> text & <i>italic</i>';
$string = htmlspecialchars($string);
$translated = strtr($string, $HTML401NamedToNumeric);
Which would return the following at each step:
- Base:
Some <b>bold</b> text & <i>italic</i>
- Special chars:
Some <b>bold</b> text & <i>italic</i>
- Translated:
Some <b>bold</b> text & <i>italic</i>
Aside from that, you really need to supply more code.
The string is required to be converted to special chars because of the way the strtr
function works by checking the array keys; and since the array keys are stored as HTML entities, this must be the case for the replacements. Ergo, removing the htmlspecialchars
line will result in the exact same string being output. This could be resolved by replacing the array keys with the actual character and not the entity, but that will require more work on your part.