Yii Framework Forum: 一个中文3个字节? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

一个中文3个字节? Rate Topic: -----

#1 User is offline   babyone 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 20-April 09

Posted 05 July 2010 - 05:59 AM

数据库中是char(30) utf8的
model中array('truename', 'length', 'max'=>30),
controller中
$user->attributes = $_POST['User'];
if ($user->validate()) $user->save();

英文没问题的可以输入30个 而中文只能输入10个
yii v1.1.2
0

#2 User is offline   surfire 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 12-September 09

Posted 07 July 2010 - 10:12 AM

UTF8 编码 一个英文字符是1个字节 一个汉字是3个字节
GBK 编码 一个英文字符和一个汉字都是2个字节
0

#3 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 07 July 2010 - 10:16 AM

你可以在rule里设置'encoding'=>'UTF-8'。缺省是按字节数验证的。
0

#4 User is offline   starsw001 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 02-March 11

Posted 04 March 2011 - 05:31 AM

这个是需要注意的地方。。。
0

#5 User is offline   cdcchen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 78
  • Joined: 28-June 09

Posted 08 March 2011 - 10:15 AM

这样不合理啊,mysql中的varchar(30),就是30个汉字,到了yii中自动生成的 max=>30,岂不是只有10个字,这样不就出错了
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users