No one seems to answer your real question, so I will
How to use htmlentities or htmlspecialchars only if it has not been used in the string yet? Is there a built-in way to detect if entities are already on the line?
It's impossible. What if I create a tutorial about HTML objects and I want to actually print this on the screen:
The Lion&
... it should be encoded as ...
The Lion’s Pride
, , ?... ..
: , , - - .
, ? , , html XML? JSON?... JSON ? .
, API, , , . API, , , . / .
, , , .