I am looking to convert a string say 'Hello' world to its ASCII value in php.
But I don't want to use ord()
. Are there any other solutions for printing ascii value without using ord()
?
unpack()
Unpacks from a binary string into an array according to the given format.
Use the format C*
to return everything as what you'd get from ord()
.
print_r(unpack("C*", "Hello world"));
Array
(
[1] => 72
[2] => 101
[3] => 108
[4] => 108
[5] => 111
[6] => 32
[7] => 119
[8] => 111
[9] => 114
[10] => 108
[11] => 100
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With