php 汉字转化成 二进制 十进制 十六进制 数目字
php 汉字转化成 二进制 十进制 十六进制 数字
<?php/** * 把一个汉字转为unicode的通用函数,不依赖任何库,和别的自定义函数,但有条件 * 条件:本文件以及函数的输入参数应该用utf-8编码,不然要加函数转换 * 其实亦可轻易编写反向转换的函数,甚至不局限于汉字,奇怪为什么PHP没有现成函数 * @author xieye * * @param {string} $word 必须是一个汉字,或代表汉字的一个数组(用str_split切割过) * @return {string} 一个十进制unicode码,如4f60,代表汉字 “你” * * @example echo "你 ".getUnicodeFromOneUTF8("你"); echo "<br />"; echo "好 ".getUnicodeFromOneUTF8("好"); echo "<br />"; echo "你好 ".getUnicodeFromOneUTF8("你好"); echo "<br />"; echo "你好吗 ".getUnicodeFromOneUTF8("你好吗"); 你 20320 好 22909 你好 251503099357000 你好吗 4.21952182258E+21 */function getUnicodeFromOneUTF8($word) { //获取其字符的内部数组表示,所以本文件应用utf-8编码! if (is_array( $word)) $arr = $word; else $arr = str_split($word); //此时,$arr应类似array(228, 189, 160) //定义一个空字符串存储 $bin_str = ''; //转成数字再转成二进制字符串,最后联合起来。 foreach ($arr as $value) $bin_str .= decbin(ord($value)); //此时,$bin_str应类似111001001011110110100000,如果是汉字"你" //正则截取 $bin_str = preg_replace('/^.{4}(.{4}).{2}(.{6}).{2}(.{6})$/','$1$2$3', $bin_str); //此时, $bin_str应类似0100111101100000,如果是汉字"你" return bindec($bin_str); //返回类似20320, 汉字"你" //return dechex(bindec($bin_str)); //如想返回十六进制4f60,用这句}echo "你 ".getUnicodeFromOneUTF8("你");echo "<br />";echo "好 ".getUnicodeFromOneUTF8("好");echo "<br />";echo "你好 ".getUnicodeFromOneUTF8("你好");echo "<br />";echo "你好吗 ".getUnicodeFromOneUTF8("你好吗");exit;?>

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

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

A bin file is a computer file format and is the abbreviation of "binary file". bin files are commonly used to store and transfer computer programs or data. In software development, the compiler converts source code into binary form and generates an executable bin file. These bin files contain the machine code of the computer program and can be run directly on the computer. Because binary files contain low-level machine instructions, they are generally more efficient and faster than text files.

bin is a binary file format; a binary file, its use depends on the system or application; a file format abbreviation of binary, a file with the suffix ".bin" just indicates that it is in binary format; for example, virtual optical drive files commonly use " .bin" as a suffix, but it does not mean that all bin files are virtual CD-ROM files; generally speaking, they are machine codes and assembly language compiled results.

Some NVIDIA Studio driver users have recently reported issues with seeing the "NODC" watermark on Adobe Premiere Pro applications. Some users also reported seeing the "YESDC" watermark as well. But, don't worry. This is all due to a corrupted bin file in NVIDIA core files. So, just find the file in File Explorer and delete the corrupted file and restart to resolve the issue. Alternatively, you can just restore the default NVIDIA3d settings. Follow these fixes to resolve the issue quickly. Fix 1 – Remove NVIDIAbin file Follow the steps below to remove it from your system

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

The method of using MDK to generate a bin file includes steps such as creating a project, writing application code, setting the output path and name, compiling and linking. Detailed introduction: 1. Open the MDK software and create a new project. Select "New Project" in the "Project" menu, and then select the model and supplier of the target device; 2. In the pop-up dialog box, select the save path and name of the project, and click the "Save" button, etc.

With the development of the Internet and the advancement of information technology, the era of big data has arrived, and fields such as data analysis and machine learning have also been widely used. In these fields, task scheduling is an inevitable problem. How to achieve efficient task scheduling is crucial to improving efficiency. In this article, we will introduce how to use Golang's web framework Echo framework to implement distributed task scheduling. 1. Introduction to the Echo framework Echo is a high-performance, scalable, lightweight GoWeb framework. It is based on HTTP

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets
