2011-11-12 7 views
0

This is the input string that I entered in my HTML form:Why does a string with the same encoding renders differently on MySQL and HTML?

ラムダ計算(λ - 、lambda - )は、関数の定義、関数の適用、誘導関数を式で表現するための形式のシステムである。 1930年代アロンゾ・チャーチが数学基礎論を研究する過程で、ラムダ計算の形式を提案し

This is the string that appears in MySQL database field of TINYTEXT type:

람ë <¤ëŒ€ì~(λ - 、lambda - )ëŠ "함ì~ì•ì~、함ì~ììš©、 ê・€ë、©ì함ì~ë¥ ¼ì~ì<으로í'œí~「í•~기ìœ「í•œí~•ì<ì²'ê³ "ì'

This is the output on the HTML page upon querying:

ラムダ計算(λ - 、lambda - )は、関数の定義、関数の適用、誘導関数を式で表現するための形式チェギェイ

Both the HTML and the database are encoded in UTF-8。 There are two things which I would like to ask:

  1. Why does the field in MySQL database render differently from the ones in HTML?
  2. What can I do to catch the length in bytes of the above string to ensure it is within the 255 limit of TINYTEXT

答えて

2

Most likely the most common pitfall:You're not setting your database connection to the right encoding。 See why do i have to use mb_convert_encoding($name,'ISO-8859-15','utf-8') to get accented chars to display?

+0

How about my second question? –

+0

Because Unicode characters store 2-3 times more bytes than ASCII、You can probably only store up to 85 ** characters **、because they can be up to 255 ** bytes **。 Use an INT。 –

+0

@Ben Since UTF-8 storage in MySQL in VARCHAR/TEXT columns is rather complex、I do not have an answer for that。 I'd suggest you do not limit yourself to TINYTEXT if you plan on storing anything more than a handful of characters。 – deceze

関連する問題