This question is solved, check my answer to see the solution
I'm trying to add to my DB a text with accented letters through an html form that submits with POST to a PHP page, the problem is that accented letters are converted to unreadable characters.
I have this form:
<form action="page.php" method="POST">
<input type="textarea" id="text1" name="text1" />
<input type="submit" value="Send" />
</form>
And then, in page.php:
echo $_POST['text1'];
The problem is that if i input àèìòù
in my textarea and then i submit the form, i get this output:
à èìòù
My next step would be convert accented letters to html entities with htmlentities($_POST['text1']
but i need $_POST
to give me the correct letters.
Note: in the page head i already have
<meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" />
How can i fix this?
EDIT
I tried with
<form action="page.php" method="POST" accept-charset="UTF-8">
<input type="textarea" id="text1" name="text1" />
<input type="submit" value="Send" />
</form>
And it didn't solve it
EDIT 2
Also tried with adding
<meta charset='utf-8'>
to my document's head, and it doesn't work
EDIT 3
I tried with setting my charset as UTF-8 on the second page too, and
echo $_POST['text1'];
displayed the correct result.
I saw that the problem is whe i use htmlentities, with this code
echo htmlentities($_POST['text1']);
I get
à èìòù
Which actually outputs
à èìòù
even if i set charset in my meta-tags and header too. Does anyone know how can i solve it?