Encoding issue using htmlentities method

I have a character encoding problem in php, so this is php code:

n_event=$_GET['ndlann']; $nom_complet=htmlentities(stripslashes($_POST['nom'])); $email_comment=htmlentities(stripslashes($_POST['email'])); $titre_comment=htmlentities(stripslashes($_POST['titre'])); $texte_comment=htmlentities(stripslashes(nl2br($_POST['commentaire']))); $pays_comment=$_POST['pays']; $date_ajout=date('Y/m/d'); 

The data will be added to the database table, you will see that this data comes from the comment form, therefore, when the user enters some comments with orientation language karachayers (Arabic, Hebrew ... etc.), the input data will change something like this :

Ø '' Ø ± ا ع 'ا ¶¶

I tried to remove the htmlentities method, and this works fine, but tackles another problem of protecting comment forms. (js scripts will be executed)

What can I do with this situation?

and thanks

+4
source share
2 answers

Do not use htmlentities () ever.

This feature has been deprecated a long time ago. Use htmlspecialchars() .

you also have tons of nonsense in your code

  • Running htmlentities(nl2br(*)) does not make sense.

  • make stripslashes conditional only if magic quotes are set.

  • there is a possible problem with the pays field.

  • I also fear that you accept htmlentities as some escaing SQL function. I'm right?

+2
source

In my opinion, and according to the PHP doc , the accepted answer is incorrect. Nowhere is it written that this feature is deprecated.

If you correctly set the third argument of the function called $encoding , it will solve your problem.

Hope this helps.

+2
source

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


All Articles