There are plenty of similar question here on StackOverlow, but could not find a solution to my particular problem.
I'm facing a challenge with encoding using PHP angle brackets (<,>) to HTML entities in a string that contains HTML content. The goal is to encode only the angle brackets not 'belonging' to any tag, while leaving the HTML tags untouched. Here's an example:
<p> sample text with equation like b<a or text <inside> brackets </p>
Regex solutions won't work because of too many variations. Tried HTMLPurifier, but it strips anything resembling tags. I think I need a smart enough DOM parser and then encode all text nodes. Any suggestions?