String and multi-digit conversion functions in PHP
Conversion function
/** * [字符串转换为(2,8,16进制)ASCII码] * @param string $str [待处理字符串] * @param boolean $encode [字符串转换为ASCII|ASCII转换为字符串] * @param string $intType [2,8,16进制标示] * @return string byte_str [处理结果] * @author alexander */ function strtoascii($str, $encode=true, $intType="2"){ if($encode == true){ $byte_array = str_split($str); foreach($byte_array as &$value){ $value = ord($value); switch ($intType) { case 16: $value = sprintf("%02x", $value); break; case 8: $value = sprintf("%03o", $value); break; default: $value = sprintf("%08b", $value); break; } } unset($value); $byte_str = implode('', $byte_array); } else{ $chunk_size = $intType == 16 ? 2 : ($intType == 8 ? 3 : 8); $byte_array = chunk_split($str, $chunk_size); $byte_array = array_filter(explode("\r\n", $byte_array)); foreach($byte_array as &$value){ $fun_name = $intType == 16 ? 'hexdec' : ($intType == 8 ? 'octdec' : 'bindec'); $value = $fun_name($value); $value = chr($value); } unset($value); $byte_str = implode('', $byte_array); } return $byte_str; }
Multi-base in PHP
PHP Integer values can be represented in decimal, hexadecimal, octal or binary, and can be preceded by an optional sign (- or +).
Binary: [+-]?0b[01]+
Octal: [+-]?0[1-7]+
Decimal: [+-]?[1-9][0-9]* |0
Hex: [+-]?[xX][0-9a-fA-F]+
Multiple base conversion function:
bindec | Binary to decimal conversion |
decbin | Convert decimal to binary |
octdec | Convert octal to decimal |
decoct | Convert decimal to octal |
hexdec | hexdec Convert system to decimal |
dechex | Convert decimal to hexadecimal |
The above introduces the string and multi-base conversion functions in PHP, including the relevant 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

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



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.

Title: Example of using the Array.Sort function to sort an array in C# Text: In C#, array is a commonly used data structure, and it is often necessary to sort the array. C# provides the Array class, which has the Sort method to conveniently sort arrays. This article will demonstrate how to use the Array.Sort function in C# to sort an array and provide specific code examples. First, we need to understand the basic usage of the Array.Sort function. Array.So

1byte equals 8bit. Data storage is in "byte" (Byte) as the unit, and data transmission is mostly in "bit" (bit) as the unit. One bit represents a 0 or 1 (that is, binary), and every 8 bits (bit) form a Byte is the smallest unit of information; therefore, "1Byte=8bit".

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

When programming in PHP, we often need to merge arrays. PHP provides the array_merge() function to complete array merging, but when the same key exists in the array, this function will overwrite the original value. In order to solve this problem, PHP also provides an array_merge_recursive() function in the language, which can merge arrays and retain the values of the same keys, making the program design more flexible. array_merge

In PHP, there are many powerful array functions that can make array operations more convenient and faster. When we need to combine two arrays into an associative array, we can use PHP's array_combine function to achieve this operation. This function is actually used to combine the keys of one array as the values of another array into a new associative array. Next, we will explain how to use the array_combine function in PHP to combine two arrays into an associative array. Learn about array_comb

Object to byte and byte to Object Today we will realize how to convert from Object to byte and how to convert from byte to Object. First, define a class student: packagecom.byteToObject;importjava.io.Serializable;publicclassstudentimplementsSerializable{privateintsid;privateStringname;publicintgetSid(){returnsid;}publicvoidsetSid(in

In PHP programming, array is a very important data structure that can handle large amounts of data easily. PHP provides many array-related functions, array_fill() is one of them. This article will introduce in detail the usage of the array_fill() function, as well as some tips in practical applications. 1. Overview of the array_fill() function The function of the array_fill() function is to create an array of a specified length and composed of the same values. Specifically, the syntax of this function is
