The problem of the Chinese string removing the integer from the mark conversion

Source: Internet
Author: User
Tags unpack
PHP Code UTF-8

The php file is known to be UTF8 encoded and is available as follows:
$data = "Medium";
Why (int) substr ($data, 0, 1) = = 0?
How can I convert to the correct integer?


Reply to discussion (solution)

Emergency, urgent and urgent

This post was last edited by xuzuning on 2013-07-23 18:25:20

$data = "Medium";
Echo Ord (substr ($data, 0, 1)); 228

Only the first digit character in a string can be converted directly to a numeric value
Echo ' 0123ABC ' +0; 123
echo (int) ' 0123ABC '; 123

How can I convert substr ($data, 0, 1) into numbers?

I don't understand what LZ is trying to do.
Take the ASCII code and then go int?

Reference function is not used, is the meaning of upstairs

Intval () or (int) since it is an ASCII code, you need Ord ()

Intval () or (int) since it is an ASCII code, you need Ord ()
I want to loop through the ASCII values for each character in the string.

I shorted out, I can take a single character of a string, and then call Ord () for each character

There's still something wrong with the feeling.

$data = "Medium"; $t = Unpack (' c* ', $data);p Rint_r ($t);
Array
(
[1] = 228
[2] = 184
[3] = 173
)
$data = "ABCD"; $t = Unpack (' c* ', $data);p Rint_r ($t);
Array
(
[1] = 65
[2] = 66
[3] = 67
[4] = 68
)

This should be done upstairs.

  • Related Article

    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.