Re-recognize unicode and utf8 encoding
Until today, just now to be precise, I didn’t know that UTF-8 encoding and Unicode encoding are different, there is a difference囧
There is a certain connection between them Yes, look at their differences:
<code>UTF-8的长度是不一定的,有可能是1、2、3字节 Unicode长度一定,2个字节(USC-2) UTF-8可以和Unicode互相转换</code>
The relationship between unicode and utf8
Unicode (16) | UTF-8 (binary) |
---|---|
0000 - 007F | 0xxxxxxx |
0080 - 07FF | 110xxxxx 10xxxxxx |
0800 - FFFF | 1110xxxx 10xxxxxx 10xxxxxx |
The above table has two meanings. The first one is obviously Unicode Correspondence to UTF-8 character range , there is another way to see how Unicode and UTF-8 can be converted to each other:
Let’s talk about the conversion from UTF-8 to Unicode first
UTF-8 encoded binary is matched with the above three formats, and the fixed bits are removed after matching (Non-x position in the table), and then every 8-bit group from right to left. If there are not enough 8-bits, the left side will not be collected. Make up 2 bytes and 16 bits. These 16 bits represent the Unicode encoding corresponding to UTF-8. , take a look at the following examples:
The text encoding format in the above picture is UTF-8, and you can use WinHex to see its hexadecimal representation
<code>字符 => UTF-8 => UTF-8二进制=> 去掉固定位置凑够16位的二进制 => 16进制 汉 => E6B189 => 11100110 10110001 10001001 => 01101100 01001001 => 6C49 汉 => E5AD97 => 11100101 10101101 10010111 => 01011011 01010111 => 5B57 #下面是在chrome命令行下面运行的结果 '\u6C49' "汉" '\u5B57' "字" #到这里的话,从UTF-8转换到Unicode已经是一件非常容易的事了,看看转换的伪代码 读取一个字节,11100110 判断该UTF-8字符的格式,属于第三种,3个字节 继续读取2个字节得到 11100101 10101101 10010111 按照格式去掉固定位 1011011 01010111 不够16位,左边补零 01011011 01010111 => 5B57</code>
Let’s look at the conversion from Unicode to UTF-8
<code>5B57 获取5B57所在的Unicode范围,0800 </code>
Let’s talk about the problem
Let’s talk about the cause of today’s problem. Many words are input from the front end. Each word in UTF-8 format has a maximum of 30 bytes, so verification will be done on the front end and backend respectively. JavaScript uses Unicode encoding. The back-end program uses UTF-8 encoding, and the current solution is as follows
Front-end
<code>function utf8_bytes(str) { var len = 0, unicode; for(var i = 0; i </code>
Backend
<code>#对于GBK字符串 $len = ceil(strlen(bin2hex(iconv('GBK', 'UTF-8', $word)))/2); #对于UTF8字符串 $len = ceil(strlen(bin2hex($word))/2);</code>
5/21/2015 8:21:53 PM
The copyright of this article belongs to the author iforever(luluyrt@163 .com), any form of reprinting is prohibited without the consent of the author. After reprinting the article, a link to the author and the original text must be provided in an obvious position on the article page, otherwise we reserve the right to pursue legal liability.
The above has introduced the re-understanding of unicode and utf8 encoding, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为GT3pro和GT4都是非常热门的选择,不少用户都很好奇华为GT3pro和GT4有什么区别,下面就就给大家介绍一下二者。华为GT3pro和GT4有什么区别一、外观GT4:46mm和41mm,材质是玻璃表镜+不锈钢机身+高分纤维后壳。GT3pro:46.6mm和42.9mm,材质是蓝宝石玻璃表镜+钛金属机身/陶瓷机身+陶瓷后壳二、健康GT4:采用最新的华为Truseen5.5+算法,结果会更加的精准。GT3pro:多了ECG心电图和血管及安

为什么截图工具在Windows11上不起作用了解问题的根本原因有助于找到正确的解决方案。以下是截图工具可能无法正常工作的主要原因:对焦助手已打开:这可以防止截图工具打开。应用程序损坏:如果截图工具在启动时崩溃,则可能已损坏。过时的图形驱动程序:不兼容的驱动程序可能会干扰截图工具。来自其他应用程序的干扰:其他正在运行的应用程序可能与截图工具冲突。证书已过期:升级过程中的错误可能会导致此issu简单的解决方案这些适合大多数用户,不需要任何特殊的技术知识。1.更新窗口和Microsoft应用商店应用程

第1部分:初始故障排除步骤检查苹果的系统状态:在深入研究复杂的解决方案之前,让我们从基础知识开始。问题可能不在于您的设备;苹果的服务器可能会关闭。访问Apple的系统状态页面,查看AppStore是否正常工作。如果有问题,您所能做的就是等待Apple修复它。检查您的互联网连接:确保您拥有稳定的互联网连接,因为“无法连接到AppStore”问题有时可归因于连接不良。尝试在Wi-Fi和移动数据之间切换或重置网络设置(“常规”>“重置”>“重置网络设置”>设置)。更新您的iOS版本:

Unicode是一种字符编码标准,用于表示各种语言和符号。要将Unicode编码转换为中文字符,可使用Python的内置函数chr()和ord()。

深入了解PHP:JSONUnicode转中文的实现方法在开发中,我们经常会遇到需要处理JSON数据的情况,而JSON中的Unicode编码在一些场景下会给我们带来一些问题,特别是当需要将Unicode编码转换为中文字符时。在PHP中,有一些方法可以帮助我们实现这个转换过程,下面将介绍一种常用的方法,并提供具体的代码示例。首先,让我们先了解一下JSON中Un

Eclipse中文乱码困扰?试试这些解决方案,需要具体代码示例一、背景介绍随着计算机技术的不断发展,中文在软件开发中扮演着越来越重要的角色。然而,很多开发者在使用Eclipse进行中文开发时会遇到乱码问题,影响了工作效率。那么,本文将介绍一些常见的乱码问题,并给出相应的解决方案及代码示例,帮助读者解决Eclipse中文乱码问题。二、常见乱码问题及解决方案文件

JSON(JavaScriptObjectNotation)是一种轻量级的数据交换格式,通常用于Web应用程序之间的数据交换。在处理JSON数据时,我们经常会遇到Unicode编码的中文字符(例如"u4e2du6587"),需要将其转换为可读的中文字符。在PHP中,我们可以通过一些简单的方法来实现这个转换。接下来,我们将详细介绍如何将JSONUnico

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download
The most popular open source editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool