PHP ord function and Chinese garbled solution _php Tutorial

Source: Internet
Author: User
PHP ord () functions the PHP string function defines and uses the Ord () function to return the ASCII value of the first character of a string. The syntax ord (string) parameter describes the string required. The string from which to get the ASCII value.

PHP Tutorial ord () function
PHP string function
Definition and usage
The Ord () function returns the ASCII value of the first character of a string.

Grammar
Ord (String) parameter description
string is required. The string from which to get the ASCII value.

Echo Ord (' I ');
Here can only return 230, I was saved by U8 file and output, it got only 230, and 230 to Hex is E6, actually U8 My code is e68891, so you understand it, in fact, it only got the first byte

echo chr (0xe6) Chr (0x88). chr (0x91);
This example can be u8 in the case of the output of my kanji, you see, here 3 times to get this kanji

A character
$str = (Pack ("A *", "China"));
echo $str, "=", strlen ($STR), "Byte n";
Getascill ($STR);
H character
$str = (Pack ("h*", "Fffe"));
echo $str, "=", strlen ($STR), "Byte n";
Getascill ($STR);
C character
$str = (Pack ("c*", "55", "56", "57"));
echo $str, "=", strlen ($STR), "Byte n";
Getascill ($STR);

I-character short-shaped 32-bit 4-byte 64-bit 8-byte
$str = (Pack ("I", "100"));
echo $str, "=", strlen ($STR), "Byte n";
Getascill ($STR);

s character short shaping 2 bytes
$str = (Pack ("s", "100"));
echo $str, "=", strlen ($STR), "Byte n";
Getascill ($STR);

L character-length shaping 4 bytes
$str = (Pack ("L", "100"));
echo $str, "=", strlen ($STR), "Byte n";
Getascill ($STR);

F-character single-precision floating-point 4 bytes
$str = (Pack ("F", "100"));
echo $str, "=", strlen ($STR), "Byte n";
Getascill ($STR);

D-character double-precision floating-point 8 bytes
$str = (Pack ("D", "100"));
echo $str, "=", strlen ($STR), "Byte n";
Getascill ($STR);

function Getascill ($STR)
{
$arr =str_split ($STR);
foreach ($arr as $v)
{
echo $v, "=", Ord ($v), "n";
}
echo "=============RNRN";
}


http://www.bkjia.com/PHPjc/445403.html www.bkjia.com true http://www.bkjia.com/PHPjc/445403.html techarticle php ord () functions the PHP string function defines and uses the Ord () function to return the ASCII value of the first character of a string. The syntax ord (string) parameter describes the string required. The word from which to get the ASCII value ...

  • 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.