5

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 concrete. http://www.phpbuilder.com/board/archive/index.php/t-10247795.html

Thanks

Community
  • 1
  • 1
Vishal
  • 51
  • 1
  • 1
  • 2

1 Answers1

4

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
)
mauris
  • 42,982
  • 15
  • 99
  • 131
jon_darkstar
  • 16,398
  • 7
  • 29
  • 37