PHP htmlentities not working even with parameters

html-entities, htmlspecialchars, php

Solution

Your code works for me :-?

In the manual page for `htmlentities()` we can read:

Return Values

Returns the encoded string.

If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set.

My guess is that the input data is not properly encoded as UTF-8 and the function is returning an empty string. (Assuming that the script is not crashing, i.e., code after that part still runs.)

Problem

Of course this has been asked before and have searched for solutions, all which have not worked thus far. I want to change out the TM symbol and the ampersand to their html equivelents by using `htmlentities` or `htmlspecialchars`: ``` $TEST = "Kold Locker™ & other stuff"; echo "ORGINIAL: " . $TEST . "<BR/>"; echo "HTML: " . htmlentities($TEST, ENT_COMPAT, 'UTF-8'); ``` This displays: ``` ORGINIAL: Kold Locker™ & other stuff HTML: ``` I have also tried it with `htmlspecialchars` and the second parameter changed with the same result. What am I missing that others have claimed worked in other solutions? UPDATE: I tried just displaying `utf8_encode($TEST)` and it displayed `HTML: Kold Locker™ & other stuff`

Original source