Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:40:24+00:00 2026-06-13T09:40:24+00:00

gb2312 is a double byte character set, using mb_strlen() to check a single chinese

  • 0

gb2312 is a double byte character set, using mb_strlen() to check a single chinese character will return 2, but for 2 more characters,sometimes the result is weird, anybody know why? how can I get the right length?

<?php
header('Content-type: text/html;charset=utf-8');//
$a="大";
echo mb_strlen($a,'gb2312'); // output 2
echo mb_strlen($a.$a,'gb2312'); // output 3 , it should be 4
echo mb_strlen($a.'a','gb2312'); // output 2, it should be 3
echo mb_strlen('a'.$a,'gb2312'); // output 3, 
?>

thanks deceze, your document is very helpful, people know little about encoding like me should read it.What every programmer absolutely, positively needs to know about encodings and character sets to work with text

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:40:25+00:00Added an answer on June 13, 2026 at 9:40 am

    Your string is probably stored as UTF-8.

    The UTF-8 code for "大" is E5 A4 A7 (according to this webpage), so:

    $a       // 3 bytes, gb2312 -> 2 char (1 + 0.5)
    $a . $a  // 6 bytes, gb2312 -> 3 char
    $a . 'a' // 4 bytes, gb2312 -> 2 char
    'a' . $a // 4 bytes, first byte is <128 so will be interpreted as one
             // single character, gb2312 -> 3 char
    

    This is just a guess, but perfectly make sense to me if thinking this way. You can probably refer to this wikipedia page.

    If you really want to test, I recommend you to create a separated file saved in gb2312 encoding, and use fopen or whatever to read it. Then you will be sure that it is in the desired encoding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In ASCII, the character < is encoded as a single-byte character 0x3C, what I'd
I am having problems in writing some Chinese characters to http response. I set
This is my code: print '哈哈'.decode('gb2312').encode('utf-8') ...and it prints: SyntaxError: Non-ASCII character '\xe5' in
I'm trying to decode a char · using charset GB2312 in java this char
Where can I find a Unicode table showing only the simplified Chinese characters? I
I am using JSoup to parse a gb2312 charset page: http://vars.sinaapp.com/u/t/jsoup_output_encoding_issue.html source code: String
>>> a = 我 # chinese >>> b = unicode(a,gb2312) >>> a.__class__ <type 'str'>
How do I convert text between multi-byte text strings, for example Simplified Chinese GB
I want to convert a big csv file from gb2312 encoding to UTF-8 encoding.
Some character not support by certain charset, so below test fail. I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.