GB18030和UTF-8有啥区别
GB18030和UTF-8的区别有:1、GB18030和UTF-8是不同的字符表示方式;2、GB18030是中国制定的标准,UTF-8是国际上的组织制定的标准;3、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,马 丹啊当个程序员,容易吗!
前者是中文字符集,后者是万国码,完全不同的字符集编码!笔者建议好好了解一下字符编码,可以参考一下这篇文章,字符编码详解
前者是字符集,相当于“都说些啥”,后者是编码方式,相当于“该咋说”。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.
