search
HomeBackend DevelopmentPHP TutorialGB18030和UTF-8有啥区别

GB18030和UTF-8有啥区别

Jun 06, 2016 pm 08:21 PM
utf-8

GB18030和UTF-8的区别有:1、GB18030和UTF-8是不同的字符表示方式;2、GB18030是中国制定的标准,UTF-8是国际上的组织制定的标准;3、GB18030是中文字符集,UTF-8是万国码。

GB18030和UTF-8有啥区别

GB18030和UTF-8有啥区别?

GB18030 是中国的标准,国标(GB),就是如何表示一个字符。Unicode只给出了一个字符的编号,并没有规定如何表示(或者说保存),UTF-8规定了如何表示。所以说,GB18030 和 unicode+utf-8 是不同的字符表示方式,一个是中国制定的标准,一个是国际上的组织制定的标准。

计算机被发明的时候,人们认为不会像现在这么流行,所以包括控制字符在内人们只定义了包括控制字符在内的128种符号,这就是 ASCII。

后来计算机流行到非英语国家,那么他们有自己的语言需要计算机显示。由于ASCII符号只有128个,而计算机一个字节有8位,所以还有128个冗余,于是他们用剩余的128个冗余表示他们自己国家的文字。不同的国家把这128个(其实是95个)定义成不同的字符,分别叫做ISO8859-1(Latin-1),ISO8859-2(Latin-2).....ISO8859-16(Latin-10)。额,中间有一部分不叫 Latin(好坑人呀)

但是在东亚,就说中国吧,128个显然表示不了所有的汉字。所以就只能用两个字节表示一个汉字。于是规定,原始的 ASCII 还是用一个字节表示,使用连续两个字节(这两个字节值都大于128)表示一个汉字。一共可以表示128×128=16384个汉字(实际没有那么多),叫做 GB2312。后来人们发现自己太傻,其实第一个字节大于128的话,我们用连续两个字节表示一个汉字也不会出现歧义,所以规定,如果当前字节小于128那么就是标准的 ASCII,如果当前字节大于128就用当前字节和后面那个字节表示一个汉字,所以可以表示(128×256=32768)个汉字,然后补充了一部分汉字,叫做 GBK。在此基础上又增加了一部分汉字,这个版本叫做 GB18030。(东亚标准里还有BIG5和CJK的故事)。

不同的国家有不同的标准,所以当大家交流的时候就不方便了。所以出现了两个组织(忘记具体叫什么了),开始着手统一全部的字符集(后来其中一个组织觉得另一个组织做就好了,主动退出了),叫做 Unicode。

但是 Unicode 只规定了一个字符的编号,并没有规定具体怎么表示。比如 A 编号65,具体表示的时候可以用一个字节 0x41 表示,可以用两个字节表示 0x00 0x41,或者用四个字节表示 0x00 0x00 0x00 0x41,而且多个字节表示的话还有谁在前的问题。所以在 unicode 表示上出现了不同的标准。UTF-8 就是一种表示的标准(终于说到UTF-8了),不过具体怎么表示就有点儿复杂了,是一种变长编码,有些字符用一个字节(兼容ASCII,这就是为什么UTF-8比较流行)有些用两个有些三个。。。随便百度了一个表示方式,就是把一个如何把一个数字转成几个字节表示。

扩展:还有两种标准 UTF-16,UTF-32,UTF-16统一个用两个字节或是四个字节表示一个字符(java,javascript里就是这种编码,这其中还有USC定长编码的故事),UTF-32统一用4个字节,所以都不兼容ASCII。既然是多字节,就涉及字节顺序的问题。。。。

非常同意 @zonxin 不过我想说:

珍爱生命,远离GBK/GB2312 (当然有点偏激, 但爷就这么说了!)

当然utf8问题,微软又整出个utf8 with bom 和 utf8 without bom,马 丹啊当个程序员,容易吗!

前者是中文字符集,后者是万国码,完全不同的字符集编码!笔者建议好好了解一下字符编码,可以参考一下这篇文章,字符编码详解

前者是字符集,相当于“都说些啥”,后者是编码方式,相当于“该咋说”。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software