You can use the chr function in PHP to convert the ascii code value into a string. The syntax of this function is "string chr (int ascii);" and its parameter "ascii" represents the ascii value that needs to be converted. .
Recommended: "PHP Video Tutorial"
Use PHP's chr and ord functions to implement strings Convert to and from ASCII codes
chr and ord functions are used to convert strings to ASCII codes.
ASCII codes are the encoding of characters that can be displayed by the computer. The value range is 0-255, including punctuation, letters, numbers, Chinese characters, etc. During the programming process, specified characters are often converted into ASCII codes for comparison.
The following is the function provided by PHP to convert ASCII codes and characters.
1. chr() function
This function is used to convert ASCII code value into a string. Its function declaration is as follows:
string chr (int ascii);
2. ord() function
This function is used to convert a string into an ASCII code value. The function declaration is as follows:
int ord(string str);
Example:
Use the chr() function and ord() function to convert between strings and ASCII codes. The program code is as follows:
<?php $str1=chr(88); echo $str1; //返回值为X echo "\t"; $str2=ord('S'); echo $str2; //返回值为83 ?>
Run result: X 83
The above is the detailed content of How to convert string in php ascii. For more information, please follow other related articles on the PHP Chinese website!