The code below converts text for characters with accents. But it also converts the HTML tags which I would like to leave intact. How can I only convert accented characters and leave all other special characters intact? Thanks.
$temp = file_get_contents("file.html");
echo htmlentities($temp,ENT_NOQUOTES,'UTF-8');
The htmlspecialchars() function converts some predefined characters to HTML entities.
The first question is: When to use the htmlspecialchars function? You use htmlspecialchars EVERY time you output content within HTML, so it is interpreted as content and not HTML. If you allow content to be treated as HTML, you have just opened the door to bugs at a minimum, and total XSS hacks at worst.
ENT_COMPAT - Default. Encodes only double quotes. ENT_QUOTES - Encodes double and single quotes. ENT_NOQUOTES - Does not encode any quotes.
htmlspecialchars()
and htmlspecialchars_decode()
will only encode/decode &
, <
, >
, '
and "
; you could thus use the latter to convert their entities back to their HTML special characters:
echo htmlspecialchars_decode(htmlentities($temp, ENT_NOQUOTES, 'UTF-8'), ENT_NOQUOTES);
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