_php tutorial for Chr (ASCII) and ord (string) function usage in PHP

Source: Internet
Author: User
Tags ord
The functions of these two functions are exactly the opposite of the CHR function, which returns characters from the specified ASCII value and the Ord () function returns the ASCII value of the first character of the string. Understand that this function is useful for everyone.

See the Chr function First

The CHR () function returns characters from the specified ASCII value.

Chr (ASCII)

The ASCII parameter can be in decimal, octal, or hexadecimal. The octal system is specified by the pre-set, and the hexadecimal is specified by the front 0x

Example

The code is as follows Copy Code

Echo Chr (52);
Echo Chr (052);
echo Chr (0x52);
?> output:

4
*
R

is not very magical, in fact, it is not my fault that I often do not see the code with CHR to operate as

The code is as follows Copy Code
Echo Chr (13);
Echo Chr (32);
?>

Let's figure out what this will do, and the result is

A carriage return, a space

Let's look at the Ord function .

The Ord () function returns the ASCII value of the first character of a string.


From above, it's just the opposite of Chr.

Grammar

The code is as follows Copy Code

Ord (String)
Example
Echo Ord ("H");
echo ord ("Hello");
?>

Output Result:

104
104

Okay, now let's look at a comprehensive example

The code is as follows Copy Code
$str 1=CHR (88);
echo $str 1; The return value is X
$str 2=CHR (Ord (X) +1); //
echo $str 2; The return value is Y
echo "T";
$str 3=ord (' S ');
echo $str 3; The return value is 83
?>

Here is an article about the PHP Ord function and Chinese garbled solution

For more detailed information, please see: http://www.bKjia.c0m/phper/php-function/php-ord.htm

http://www.bkjia.com/PHPjc/631668.html www.bkjia.com true http://www.bkjia.com/PHPjc/631668.html techarticle The functions of these two functions are exactly the opposite of the CHR function, which returns characters from the specified ASCII value and the Ord () function returns the ASCII value of the first character of the string. Understand that this function is useful for everyone. ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.