ascii码的汉字疑问。网上看到的一个代码,该怎么解决
ascii码的汉字疑问。网上看到的一个代码
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php /**** ASCII 转 十六进制 以及 十六进制 转 ASCII* 非盈利组织或个人请放心转载,商业用途请征得作者同意**///ASCII 转 十六进制function asc2hex($str) {return '\x'.substr(chunk_split(bin2hex($str), 2, '\x'),0,-2);}//十六进制 转 ASCIIfunction hex2asc($str) {$str = join('',explode('\x',$str));$len = strlen($str);for ($i=0;$i<$len;$i+=2) $data.=chr(hexdec(substr($str,$i,2)));return $data;}$asc = "哈哈";$hex = asc2hex($asc);$asc = hex2asc($hex);echo "hex : ".$hex;echo "<br>";echo "asc : ".$asc;?>
保存采用utf8保存,
问题1不明白 哈哈 是utf8编码??为什么函数可以说是ascii转16进制。 结果是\xe5\x93\x88\xe5\x93\x88
我查过哈哈的ascii码的16进制表现形式是 54c8 54c8 ,明显不一样
搞不懂
------解决方案--------------------
这里用"ascii"显然不合适,"转16进制"这么说也不合适,
函数的作用其实是: 把字符串的编码用16进制的形式表示出来
所以你的疑问都有道理.
函数头上写"非盈利组织或个人请放心转载,商业用途请征得作者同意"也很搞笑,
因为这样简单的代码没有独创性, 别人不需要看也能写出一样的代码,
所以也当然不需要"征得作者同意"

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











One ascii character occupies 1 byte. ASCII code characters are represented by 7-bit or 8-bit binary encoding in the computer and are stored in one byte, that is, one ASCII code occupies one byte. ASCII code can be divided into standard ASCII code and extended ASCII code. Standard ASCII code is also called basic ASCII code. It uses 7-bit binary numbers (the remaining 1 binary digit is 0) to represent all uppercase and lowercase letters, and the numbers 0 to 9. Punctuation marks, and special control characters used in American English.

ASCII value conversion in PHP is a problem often encountered in programming. ASCII (American Standard Code for Information Interchange) is a standard encoding system for converting characters into numbers. In PHP, we often need to convert between characters and numbers through ASCII code. This article will introduce how to convert ASCII values in PHP and give specific code examples. 1. Change the characters

This article will explain in detail the ASCII value of the first character of the string returned by PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP returns the ASCII value of the first character of a string Introduction In PHP, getting the ASCII value of the first character of a string is a common operation that involves basic knowledge of string processing and character encoding. ASCII values are used to represent the numeric value of characters in computer systems and are critical for character comparison, data transmission and storage. The process of getting the ASCII value of the first character of a string involves the following steps: Get String: Determine the string for which you want to get the ASCII value. It can be a variable or a string constant

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

1The basic unit of Unicode computer storage is the byte, which is composed of 8 bits. Since English only consists of 26 letters plus a number of symbols, English characters can be stored directly in bytes. But other languages (such as Chinese, Japanese, Korean, etc.) have to use multiple bytes for encoding due to the large number of characters. With the spread of computer technology, non-Latin character encoding technology continues to develop, but there are still two major limitations: no multi-language support: the encoding scheme of one language cannot be used in another language and there is no unified standard: for example There are many encoding standards in Chinese such as GBK, GB2312, GB18030, etc. Since the encoding methods are not unified, developers need to convert back and forth between different encodings, and many errors will inevitably occur.

The differences between unicode and ascii include different encoding ranges, different storage spaces, and different compatibility. Detailed introduction: 1. The encoding range is different. The encoding range of ASCII is 0-127, which is mainly used to represent English letters. The encoding range of Unicode is much wider and can represent almost all language characters; 2. The storage space is different. ASCII usually Use 1 byte to store a character, while unicode may use 2 or more bytes to store a character; 3. Different compatibility, etc.

"How to accurately convert PHP strings to ASCII codes, specific code examples are needed" In the field of programming, ASCII (American Standard Code for Information Interchange) code is the standard encoding system used to represent characters in computer systems. In PHP, we often need to convert strings into ASCII codes for some operations or processing. Here's how to accurately convert a string to ASCII in PHP

What are the similarities and differences between __str__ and __repr__? We all know the representation of strings. Python's built-in function repr() can express objects in the form of strings to facilitate our identification. This is the "string representation". repr() obtains the string representation of an object through the special method __repr__. If __repr__ is not implemented, when we print an instance of a vector to the console, the resulting string may be. >>>classExample:pass>>>print(str(Example()))>>>
