1

I have a form sending data to a mySQL database. But when I enter some text like "Jack&Jones", the special characters get transformed into HTML special chars (here, the & becomes "&").

The data inserted in this database can later be used to generate Word documents using a template, but these HTML characters are read wrong and the resulting file is completely messed up.

I tried to resolve the problem by ensuring all my pages used the <meta charset="UTF-8"> tag and by using header("Content-Type: text/html; charset=utf-8"); to ensure that the data keeps the UTF-8 encoding during the whole process, but it did not work.

So my question is: how do I ensure the encoding consistency between my form, my database and my word document ?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Gaëtan
  • 779
  • 1
  • 8
  • 26

2 Answers2

0

you can use

htmlspecialchars($_REQUEST['your_field'], ENT_QUOTES)

for text decode

Dry7
  • 861
  • 1
  • 8
  • 17
0

You can try this it will helps to you: For Decode text :

   htmlspecialchars("Jack&Jones", ENT_QUOTES);

For Decode the text like below, than you can use below :

   <?php
      $str = "This is some &lt;b&gt;bold&lt;/b&gt; text.";
     echo htmlspecialchars_decode($str);
   ?>
smita
  • 298
  • 1
  • 4
  • 17