Drupal编码和节点插入 [英] Drupal encoding and node insert

查看:126
本文介绍了Drupal编码和节点插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于存储提示的CCK类型(社交媒体搜索提示)。我相信的一些提法是ASCII(我对这个东西的知识很少)。



我从API检索数据,然后使用node_save保存到Drupal。 / p>

我的问题是,我应该使用什么来安全地转换任何我变成一个格式Drupal和MySQL都很高兴?



我得到的特定db_query错误是unhelpfull警告在test1 \includes\common.inc在第3538行。尼斯。我跟踪它是编码,因为我使用下面的代码,使输入安全,但它不工作与所有输入。

  $ node-> title = htmlentities($ item ['title'],ENT_COMPAT,'UTF-8'); 

对于一些ASCII字符,



我真的被卡住了。 :(



更新:我从PHP获得的EXACT错误是警告在D:\sites\test1\includes\common.inc在第3538行 ,并且该行显示if(db_query($ query,$ values))。



更新2:我已经确认数据的编码接收是UTF8,这真的没有意义,我已经确认db中的排序规则是utf8_general_ci。



更新3:标题之一是:


p> var_export(array_map('ord',str_split($ node-> title))


给了我160个字符问号(这是一个像eclipse中的[]的正方形)。



更新4:MySQL版本是5.1.41,列上的排序规则是utf8_general_ci。 p>

更新5:我设法让Drupal用db_queryd打印查询。有趣的是现在我得到确切的错误消息,而不是警告,但Drupal仍然' t在日志中有这个错误! WTF。所以确切的sql是:

  INSERT INTO节点(vid,类型,语言,标题,uid,状态,评论,推广,中度,粘性,tnid,翻译)VALUES(0,'sm_mention','','多少钱Facebook粉丝费用? 1298395302,0,0,0,0,0,0)

出现的错误是:字符串值:'\xA0 $ 1.0 ...'for row'title'in row 1



这听起来似乎不像扩展ascii字符。 p>

UPDATE 6:

  SHOW CREATE TABLE节点:$ b​​ 
$ b CREATE TABLE`node`(
`nid` int(10)unsigned NOT NULL AUTO_INCREMENT,
`vid` int(10)unsigned NOT NULL DEFAULT'0',
` `varchar(32)NOT NULL DEFAULT'',
`language` varchar(12)NOT NULL DEFAULT'',
` uid` int(11)NOT NULL DEFAULT'0',
`status` int(11)NOT NULL DEFAULT'1',
`created` int b $ b`changed` int(11)NOT NULL DEFAULT'0',
`comment` int(11)NOT NULL DEFAULT'0',
` 0',
`moderate` int(11)NOT NULL DEFAULT'0',
`sticky` int(11)NOT NULL DEFAULT'0',
`tnid` int unsigned NOT NULL DEFAULT'0',
`translate` int(11)NOT NULL DEFAULT'0',
PRIMARY KEY(`nid`),
UNIQUE KEY`vid` `),
KEY`node_changed`(`changed`),
KEY`node_created`(`created`),
KEY`node_moderate` `node_promote_status`(`promote`,`status`),
KEY`node_status_type`(`status`,`type`,`nid`),
KEY`node_title_type` (4)),
KEY`node_type`(`type`(4)),
KEY`uid`(`uid`),
KEY`tnid` ,
KEY`translate`(`translate`)
)ENGINE = InnoDB AUTO_INCREMENT = 1700 DEFAULT CHARSET = utf8

$ b b

解决方案

\xA0 不是 UTF8 序列。



NO-BREAK SPACE > Unicode codeepoint 0x00A0 应编码为 0xC2A0 UTF8



因此,你的输入字符串被破坏了,它不是有效的 UTF8


I have a CCK type for storing mentions (Social Media search mentions). Some of the mentions I believe are ASCII (My knowledge of this stuff is little).

I retrieve data from API's, which I then using node_save to save to Drupal.

My question is, what should I use to safely convert whatever I am getting into a format Drupal and MySQL are happy with?

The particular db_query error I get is unhelpfull "Warning in test1\includes\common.inc on line 3538". Nice. I have traced it to be encoding, as I used the following code to make the input safe, but it is not working with all input.

$node->title = htmlentities($item['title'], ENT_COMPAT, 'UTF-8');

It worked well for some ASCII characters, like those square ones [] etc, but not for this "行けなくてもずっとユーミンは聴きつづけます".

I'm really stuck. :(

UPDATE: The EXACT error I get from PHP is "Warning in D:\sites\test1\includes\common.inc on line 3538", and the line reads "if (db_query($query, $values)) {".

UPDATE 2: I've confirmed that the encoding of the data I am receiving is UTF8. This really doesn't make sense now, and I've confirmed that the collation in the db is utf8_general_ci.

UPDATE 3: One of the title's is: How Much Does A Facebook Fan Cost?� $1.07

The output of:

var_export(array_map('ord', str_split($node->title))

gave me the character 160 for the funny question mark (which is a square like [] in eclipse).

UPDATE 4: MySQL version is 5.1.41, and the collation on the columns is utf8_general_ci.

UPDATE 5: I managed to get Drupal to print the query with db_queryd. Funny thing is now I get the exact error message and not "Warning in", but Drupal still doesn't have this error in the log! WTF. So the exact sql is:

INSERT INTO node (vid, type, language, title, uid, status, created, changed, comment, promote, moderate, sticky, tnid, translate) VALUES (0, 'sm_mention', '', 'How Much Does A Facebook Fan Cost?� $1.07 (Geoffrey A. Fowler/Digits)', 1, 1, 1298395302, 1298395302, 0, 0, 0, 0, 0, 0)

And the error given is: Incorrect string value: '\xA0 $1.0...' for column 'title' at row 1

This honestly sounds like something doesn't like extended ascii characters.

UPDATE 6:

 SHOW CREATE TABLE node: 

   CREATE TABLE `node` (
  `nid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `vid` int(10) unsigned NOT NULL DEFAULT '0',
  `type` varchar(32) NOT NULL DEFAULT '',
  `language` varchar(12) NOT NULL DEFAULT '',
  `title` varchar(255) NOT NULL DEFAULT '',
  `uid` int(11) NOT NULL DEFAULT '0',
  `status` int(11) NOT NULL DEFAULT '1',
  `created` int(11) NOT NULL DEFAULT '0',
  `changed` int(11) NOT NULL DEFAULT '0',
  `comment` int(11) NOT NULL DEFAULT '0',
  `promote` int(11) NOT NULL DEFAULT '0',
  `moderate` int(11) NOT NULL DEFAULT '0',
  `sticky` int(11) NOT NULL DEFAULT '0',
  `tnid` int(10) unsigned NOT NULL DEFAULT '0',
  `translate` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`nid`),
  UNIQUE KEY `vid` (`vid`),
  KEY `node_changed` (`changed`),
  KEY `node_created` (`created`),
  KEY `node_moderate` (`moderate`),
  KEY `node_promote_status` (`promote`,`status`),
  KEY `node_status_type` (`status`,`type`,`nid`),
  KEY `node_title_type` (`title`,`type`(4)),
  KEY `node_type` (`type`(4)),
  KEY `uid` (`uid`),
  KEY `tnid` (`tnid`),
  KEY `translate` (`translate`)
) ENGINE=InnoDB AUTO_INCREMENT=1700 DEFAULT CHARSET=utf8

解决方案

\xA0 is not a valid start of a UTF8 sequence.

The character known as NO-BREAK SPACE having the Unicode codepoint 0x00A0 should be encoded as 0xC2A0 in UTF8.

Thus said, your input string is broken, it's not a valid UTF8.

这篇关于Drupal编码和节点插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆