I have an array of bytes that I’d like to map to their ASCII equivalents.
How can I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If by array of bytes you mean:
array_map()
Then it’s as simple as:
foreach()
Which is the compact version of:
pack()
But the most advisable alternative could be to use
pack("C*", [$array...]), even though it requires a funky array workaround in PHP to pass the integer list:That construct is also more useful if you might need to switch from bytes C* (for ASCII strings) to words S* (for UCS2) or even have a list of 32bit integers L* (e.g. a UCS4 Unicode string).