Php solves the problem of Incorrect string value: & #39; \ xF0 \ x9F \ x92 \ x8BTi... & #39; error, xf0x9f

Source: Internet
Author: User
Tags php database

Php solves the problem of Incorrect string value: '\ xF0 \ x9F \ x92 \ x8BTi...' when inserting MySQL Data. xf0x9f

When inserting data into MySQL in the project, it is found that the data insertion is incomplete. Through debugging, it is found that the insert statement has no special errors. However, if the difference does not exist, debug the mysqli error.

$ret = mysqli_query($this->conn, $sql) or die(mysqli_error($this->conn));


The following error message is displayed:

Incorrect string value: '\ xF0 \ x9F \ x92 \ x8BTi ...'


If there is an error message, you can check the result online. The result is that the mysql encoding format is UTF-8, and four-byte string insertion is not supported.


There are two methods available on the Internet:

1. Upgrade MySQL and change the corresponding data type to utf8mb4.

2. The four-byte UTF-8 character appears to filter or convert to custom type


Because MySQL 5.1 is installed, method 1 is not suitable. I chose the second filter string to convert it into a suitable 3-byte UTF-8

$str = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);

Although it still cannot be solved perfectly, at least ensure that each piece of data can be correctly inserted!

If you want to solve the problem perfectly, you 'd better upgrade MySql and change the data type to utf8mb4.





The incorrect string value problem occurs when importing data in mysql.

Use show variables like 'character % 'to view the database encoding;
View the encoding of file C:/data/201109/all.txt,
The two are the same.
You can use the alter table name convert to character set encoding format. It is best to back up data in advance to avoid exceptions.
Save the file directly and select encoding. UTF-8 whenever possible

Php Database Error insert: Incorrect string value

The following content is to be inserted: Yingde is the hometown of sugar oranges in China ". Change $ contentsql: 1. $ contentsql = "insert into '$ contenttable' ('nid ',

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.