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.