echo htmlentities($str, ENT_QUOTES, "UTF-8"); // Will only convert double quotes (not single quotes), and uses the character-set Western European. The HTML output of the code above will be (View Source): <! DOCTYPE html> <html>
htmlentities() Function: The htmlentities() function is an inbuilt function in PHP that is used to transform all characters which are applicable to HTML entities. This function converts all characters that are applicable to HTML entities. Syntax: string htmlentities( $string, $flags, $encoding, $double_encode )
There are two methods. One is by using "HTML entities." You need to enter them as, for example, é . Here is a comprehensive reference of named entities; you can also reference the Unicode code point of a given character, using its decimal form as Ӓ or its hex form as Ӓ .
Description. The htmlspecialchars() function is used to converts special characters ( e.g. & (ampersand), " (double quote), ' (single quote), < (less than), > (greater than)) to HTML entities ( i.e. & (ampersand) becomes &, ' (single quote) becomes ', < (less than) becomes < (greater than) becomes > ).
I'm having a problem with PHP's htmlentities
and the é character. I know it's some sort of encoding issue I'm just overlooking, so hopefully someone can see what I'm doing wrong.
Running a straight htmlentities("é")
does not return the correct code as expected (either é
or é
. I've tried forced the charset to be 'UTF-8' (using the charset parameter of htmlentities) but the same thing.
The ultimate goal is to have this character sent in an HTML email encoded in 'ISO-8859-1'. When I try to force it into that encoding, same issue. In the source of the email, you see é, and in the HTML view é
.
Who can shed some light on my mistake?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With