如何在没有ord()的PHP中将字符串转换为ASCII值? [英] How to convert a string to ASCII value in PHP without ord()?

查看:105
本文介绍了如何在没有ord()的PHP中将字符串转换为ASCII值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个将字符串'Hello'world转换为php中的ASCII值的方法. 但是我不想使用ord().还有其他不使用ord()来打印ascii值的解决方案吗?

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.

使用格式 C*返回您从ord()获得的一切.

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
)

这篇关于如何在没有ord()的PHP中将字符串转换为ASCII值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆