Home > Backend Development > PHP Problem > How to convert octal to string in php

How to convert octal to string in php

青灯夜游
Release: 2023-03-15 07:38:01
Original
2520 people have browsed it

Conversion method: 1. Use the base_convert() function to convert octal to hexadecimal, the syntax is "base_convert(octal string, 8,16)"; 2. Use the hex2bin() function to convert octal to hexadecimal. System to string, the syntax is "hex2bin (hexadecimal value)".

How to convert octal to string in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php converts octal to string

Implementation idea:

  • Use the base_convert() function to convert octal to hexadecimal

  • Use the hex2bin() function to convert hexadecimal to a string

<?php
$oct = "6414533066157";
$hex = base_convert($oct,8,16);
$str = hex2bin($hex);
echo $str;
?>
Copy after login

How to convert octal to string in php

Explanation: The

base_convert() function can be used in any Convert numbers between systems.

Syntax:

base_convert(number,frombase,tobase);
Copy after login
ParametersDescription
numberRequired. Specifies the number to be converted.
frombaseRequired. Specifies the original base of the number. Between 2 and 36 (inclusive). Numbers above decimal are represented by the letters a-z, such as a for 10, b for 11, and z for 35.
tobaseRequired. Specifies the base to be converted. Between 2 and 36 (inclusive). Numbers above decimal are represented by the letters a-z, such as a for 10, b for 11, and z for 35.

hex2bin() function converts a string of hexadecimal values ​​into ASCII characters, which is an ordinary string.

Syntax:

hex2bin(string)
Copy after login
Parameters Description
string Required. The hexadecimal value to convert.

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to convert octal to string in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template