Character conversion php
<code>图解ASCII码对照表图,以字符A为例 Dec表示十进制,如<span>65</span> Hx表示十六进制,如<span>41</span> Oct表示八进制,如<span>101</span> Char表示显示字符,如A ASCII码对照表图分为两个单元 <span>1</span>,控制字符 <span>0</span>-<span>31</span>和<span>127</span><span>2</span>,可显示字符 <span>32</span>-<span>126</span> (<span>1</span>)<span>48</span>~<span>57</span>为<span>0</span>到<span>9</span>十个阿拉伯数字; (<span>2</span>)<span>65</span>~<span>90</span>为<span>26</span>个大写英文字母; (<span>3</span>)<span>97</span>~<span>122</span>号为<span>26</span>个小写英文字母; (<span>4</span>)其它标点符号、运算符号等; 三,PHP字符转换函数说明 具体字符转换函数说明请参考[PHP函数篇详解十进制、二进制、八进制和十六进制转换函数说明] 十进制转二进制 decbin() 函数 十进制转八进制 decoct() 函数 十进制转十六进制 dechex() 函数 二进制转十六制进 bin2hex() 函数 二进制转十制进 bindec() 函数 八进制转十进制 octdec() 函数 十六进制转十进制 hexdec()函数 任意进制转换 base_convert() 函数 字符转换实例 实例一,如何把一个字符转换为二进制、八进制或十六进制,可以使用ord()函数先把字符转换为ASCII值,然后使用相应的进制转换函数进行转换,如下 a 这个字符转换为其二进制/八进制/十六进制,如下 a字符的十进制:ord(<span>'a'</span>); <span>//输出97</span> 二进制:decbin(ord(<span>'a'</span>)); <span>//输出1100001</span> 八进制:decoct(ord(<span>'a'</span>)); <span>//输出141</span> 十六进制:dechex(ord(<span>'a'</span>)); <span>//输出61</span>然后可以通过把各进制输出的结果对应上面ASCII码对照表图进行核对。 实例二,如何把一个二进制转换为十六进制或十进制,如a的二进制,如下 采用实例一的方法获取a字符的二进制 decbin(ord(<span>'a'</span>)); 然后把二进制转换为十六进制或十进制 十六进制:bin2hex(decbin(ord(<span>'a'</span>)));<span>//输出31313030303031</span> 二进制J:bindec(decbin(ord(<span>'a'</span>))); <span>//输出97</span></code>
<code><span>1</span>.chr()函数 该函数用于将ASCII码值转化为字符串。其函数声明如下: string chr (int ascii); <span>2</span>.ord()函数 该函数用于将字符串转化为ASCII码值。其函数声明如下: int ord(string str); 示例: 使用chr()函数和ord()函数进行字符串与ASCII码之间的转换,程序代码如下: <span><?php </span><span>$str1</span>=chr(<span>88</span>); <span>echo</span><span>$str1</span>; <span>//返回值为X</span><span>echo</span><span>"\t"</span>; <span>$str2</span>=ord(<span>'S'</span>); <span>echo</span><span>$str2</span>; <span>//返回值为83</span><span>?></span></span></code>
<code>** bin2hex() 函数把 ASCII 字符的字符串转换为十六进制值。 bin2hex(string) 参数 描述 string 必需。要转换的字符串。 字符串可通过使用 pack() 函数再转换回去。 pack() 函数把数据装入一个二进制字符串。 pack(format,args+) 参数 描述 format 必需。规定在包装数据时所使用的格式。 args+ 可选。规定被包装的一个或多个参数。 ** <span>$string</span> = <span>"Hello\tworld!\n"</span>; <span>print</span>(<span>$string</span>.<span>"\n"</span>); <span>print</span>(bin2hex(<span>$string</span>).<span>"\n"</span>); ==================================================== ---- 输出的结果: ---- ---- Hello world! ---- ---- <span>48656</span>c6c6f09776f726c64210a ==================================================== 把 <span>"Shanghai"</span> 转换为十六进制值: <span><?php </span><span>$str</span> = <span>"Shanghai"</span>; <span>echo</span> bin2hex(<span>$str</span>) . <span>"<br>"</span>; <span>echo</span> pack(<span>"H*"</span>,bin2hex(<span>$str</span>)) . <span>"<br>"</span>; <span>?></span> ==================================================== ---- 输出的结果: ---- <span>5368616e67686169</span> ---- Shanghai ==================================================== </span></code>
Copyright Statement: Everything is for learning
The above introduces the character conversion PHP, including aspects of the content, I hope it will be helpful to friends who are interested in PHP tutorials.

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

Convert basic data types to strings using Java's String.valueOf() function In Java development, when we need to convert basic data types to strings, a common method is to use the valueOf() function of the String class. This function can accept parameters of basic data types and return the corresponding string representation. In this article, we will explore how to use the String.valueOf() function for basic data type conversions and provide some code examples to

Method of converting char array to string: It can be achieved by assignment. Use {char a[]=" abc d\0efg ";string s=a;} syntax to let the char array directly assign a value to string, and execute the code to complete the conversion.

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.

Replace characters (strings) in a string using Java's String.replace() function In Java, strings are immutable objects, which means that once a string object is created, its value cannot be modified. However, you may encounter situations where you need to replace certain characters or strings in a string. At this time, we can use the replace() method in Java's String class to implement string replacement. The replace() method of String class has two types:

Hello everyone, today I will share with you the basic knowledge of Java: String. Needless to say the importance of the String class, it can be said to be the most used class in our back-end development, so it is necessary to talk about it.

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

In Golang programming, byte, rune and string types are very basic and common data types. They play an important role in processing data operations such as strings and file streams. When performing these data operations, we usually need to convert them to each other, which requires mastering some conversion skills. This article will introduce the byte, rune and string type conversion techniques of Golang functions, aiming to help readers better understand these data types and be able to apply them skillfully in programming practice.

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ
