0

there is text box of length size 10 characters and we are printing the text character counter also which display the no of character left in the text box.

if we are using ascii or UTF8 charctaers then it will displaying exact character-counter also. But in back end side it can save 10 characters size only. since UTF8 charcater is 2 byte per character.So if I put 10 UTF8 character in text box. It size will be 20 and it is not able to store in the database.

Devendra Singh
  • 327
  • 2
  • 4
  • 12

1 Answers1

1

According to this, MySQL 4 counts bytes in VARCHAR fields, while MySQL 5 counts characters. So this should work on MySQL 5. On MySQL 4, just make your field longer (make it a VARCHAR(40) and you are guaranteed it will be enough for 10 UTF-8 characters).

By the way, UTF-8 characters are not necessarily 2 bytes long. Some are 1 byte long, some can be longer than 2 bytes. All ASCII characters are 1 byte long when encoded in UTF-8.

Community
  • 1
  • 1
zmbq
  • 38,013
  • 14
  • 101
  • 171