php 相当于 java getBytes()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4226477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:24:01  来源:igfitidea点击:

php equivalent of java getBytes()

javaphp

提问by Vishal

Possible Duplicate:
String to byte array in php

可能的重复:
字符串到 php 中的字节数组

I am trying to find a php equivalent function of java getBytes() Havent found anything yet but found some answers, nothing concrete. http://www.phpbuilder.com/board/archive/index.php/t-10247795.html

我正在尝试找到 java getBytes() 的 php 等效函数还没有找到任何东西,但找到了一些答案,没有具体的答案。 http://www.phpbuilder.com/board/archive/index.php/t-10247795.html

Thanks

谢谢

回答by jon_darkstar

You mean the string function right?

你是说字符串函数吧?

$string = "texttexttext";
$bytes = array();
for($i = 0; $i < strlen($string); $i++){
     $bytes[] = ord($string[$i]);
}
print_r($bytes);

--Output--

- 输出 -

Array
(
[0] => 116
[1] => 101
[2] => 120
[3] => 116
[4] => 116
[5] => 101
[6] => 120
[7] => 116
[8] => 116
[9] => 101
[10] => 120
[11] => 116
)