The problem of converting an integer using a subscript for a Chinese string

Source: Internet
Author: User
Chinese character string subscript conversion integer problem PHP coding UTF-8

It is known that the php file is UTF-8 encoded, and the following content is available:
$ Data = "medium ";
Why (int) substr ($ data, 0, 1) = 0?
How can I convert it to a correct integer?


Reply to discussion (solution)

Quick response

This post was last edited by xuzuning at 18:25:20

$ Data = "medium ";
Echo ord (substr ($ data, 0, 1); // 228

Only digits starting with a string can be directly converted to numeric values.
Echo '0123abc' + 0; // 123
Echo (int) '0123abc'; // 123

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

I don't understand what lz really wants.
Get the ASCII code and convert it to int?

The reference function is useless.

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 obtain the ascii value of each character in the string cyclically

I am short-circuited. I can take a single character of the string first, and then call ord () for each character ()

I think there is still a problem.

$ Data = "medium"; $ t = unpack ('C * ', $ data); print_r ($ t );
Array
(
[1] => 228.
[2] => 184.
[3] = & gt; 173
)
$data = "ABCD";$t = unpack('C*', $data);print_r($t);
Array
(
[1] => 65
[2] => 66
[3] => 67
[4] => 68
)

This should be done upstairs.

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.