Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htmlentities destroys utf-8 strings

Tags:

php

I got something weird happening here and I can't understand why, on my php 5.2.5 server (Just on Linux ,Windows php servers doesn't have same problem) When I use a POST Form to post the content on an input containing "é" and on the other side I

echo(htmlentities($_POST["myinput"]))  

it echos é

But if I echo my

$_POST["myinput"]  

simply it shows "é", so this mean my htmlentities doesn't use UTF-8 by default, where can I change the Charset used by htmlentities?

I tried changing it in my php.ini default_charset = "UTF-8", but it won't work either?

like image 725
Dominique Avatar asked Apr 15 '11 16:04

Dominique


People also ask

What's the difference between Htmlentities () and htmlspecialchars ()?

Difference between htmlentities() and htmlspecialchars() function: The only difference between these function is that htmlspecialchars() function convert the special characters to HTML entities whereas htmlentities() function convert all applicable characters to HTML entities.

What is the purpose of Htmlentities () function?

The htmlentities() function converts characters to HTML entities.


1 Answers

htmlspecialchars($str, ENT_QUOTES, "UTF-8")

This is also better at preventing xss than just htmlentities()

like image 108
rook Avatar answered Sep 27 '22 23:09

rook