开发者

php equivalent of java getBytes() [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

String to byte array in php

I am trying to find a php equivalent function of java getBytes() Havent found anything yet but found some answers, nothing co开发者_运维百科ncrete. http://www.phpbuilder.com/board/archive/index.php/t-10247795.html

Thanks


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
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜