Text Encoding in HTML Text Fields

I have a website on which there is a form. POST form for php script, which then inserts data into my database. The page has the attribute charset = UTF-8 in the <meta> tag, and the database is configured to use UTF-8. However, when I copy and paste characters from MS Word into the field, the output is messed up.

For example, quotation marks in

I am using "Microsoft Word" '' ''

to become

I am using "Microsoft Word"

in the database.

Can anyone understand why this could happen?

+3
source share
6 answers

Here is what I suggest you do to find where the problem is.

  • MySQL charset Latin1 / . , . UTF8/collation utf8_unicode_ci (. http://dev.mysql.com/doc/refman/5.0/en/create-database.html).

    CREATE DATABASE example DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci;

  • MySQL / UTF8. SQL- MySQL SET NAMES UTF8; . MySQL, / UTF8. . mysql_query("SET NAMES 'UTF8'");, .

  • , UTF8. UTF8 <meta>, . , UTF8, header('Content-Type: text/html; charset=utf-8'); PHP.

+2

set names utf8

0

, . (30 ): MS Word, , , editpad pro notepad ++, . .

, MS WORD.

0

java webapp, , . :

  • db UTF-8 ( MySQL).
  • URL- db, UTF-8 URL- ( MySQL Connector-J)
  • , UTF-8.
  • HTML-, UTF-8.
0

<textarea> WYSIWYG? WYSIWYG JavaScript .

Have you tried it in different browsers? It could be a bug with a specific browser. Also, try setting the headers in PHP instead of the meta tag, as your server may send conflicting headers.

header('Content-Type: text/html; charset=utf-8'); 

What happens if you save the $ _POST data to a file? Does the encoding look normal?

file_put_contents('post.log', print_r($_POST, true));

Then, what happens if you copy text from Word to a text file and paste the contents of the file into the database?

$db_query = 'INSERT INTO table SET col="' . mysql_real_escape_string(file_get_contents('input.txt')) . '"';
0
source

to try

<form action="form_action.php" accept-charset="UTF-8">
0
source

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


All Articles