Convert special characters to PHP

I have already tried many functions, but I just can't figure it out. In any case, the right way.

In a form field called a description, I can expect all kinds of characters. They must be formatted in HTML objects before being sent to db.

Now my code is:

$formdesc = htmlentities($_POST['formdesc'], ENT_QUOTES);

For a MySQL query, I just add a "safe" function to cut "off the string":

mysql_real_escape_string($formdesc);

However, this sometimes does not work. "é", for example, becomes & Atilde; & copy; instead of & eacute ;.

To do this, there must be a normal function. Does anyone know what I mean?

+3
source share
3 answers

htmlentities ( UTF-8):

$formdesc = htmlentities($_POST['formdesc'], ENT_QUOTES, 'UTF-8');

ISO-8859-1, é , UTF-8 0xC3A9, (Ã ©).

htmlentities? HTML, &, <, >, " ' htmlspecialchars .

+13

, escaping PHP utf-8. , UTF-8 JavaScript, PHP Non-UTF8 . utf-8 PHP PHP UTF-8 cheatsheet.

+1

Source: https://habr.com/ru/post/1711556/


All Articles