Here is the function:
If you want to test it, you can do it here:
Output with encoded entities (you will not see any change compared to the input)
This is the code for the code playground above. As you can see it is very simple.