列值

时间:2015-07-23 10:59:25

标签: php mysql mysqli utf-8

我正在用PHP创建一个票证系统,它使用imap从Exchange服务器获取邮件。

当我将电子邮件中的HTML消息放入MySQL数据库时,如果消息正文中有特殊字符,例如è:

,则会出现以下错误
Incorrect string value: '\xE8. ' for column 'message' at row 1

我已经尝试了类似的东西:

utf8_encode($message);

但是这只是从消息中删除了不应该发生的所有HTML。

MySQL表:

mysql> show create table crm.tickets;
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table   | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tickets | CREATE TABLE `tickets` (
  `id` int(100) NOT NULL AUTO_INCREMENT,
  `senderName` varchar(40) DEFAULT NULL,
  `senderEmail` varchar(60) DEFAULT NULL,
  `companyID` int(15) DEFAULT NULL,
  `userID` int(15) DEFAULT NULL,
  `subject` varchar(100) DEFAULT NULL,
  `message` longtext,
  `timestamp` int(60) DEFAULT NULL,
  `toName` varchar(120) DEFAULT NULL,
  `toEmail` varchar(60) DEFAULT NULL,
  `ownerID` int(11) DEFAULT NULL,
  `ticketStatus` int(1) DEFAULT NULL,
  `ticketType` int(2) DEFAULT NULL,
  `timeSpend` int(10) DEFAULT NULL,
  `locked` int(1) DEFAULT NULL,
  `queue` int(3) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 |
+---------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

有人有任何想法吗?

1 个答案:

答案 0 :(得分:0)

我创建了一个自己的函数来将所有Microsoft字符替换为HTML字符。 像魅力一样工作!