arrays - PHP print hex values of characters in a string -
i want print hexadecimal values of each of characters in php string. example, want display hex values of each character in string i'm trying set fourth character control-c (0x03).
$str=sprintf('ab1%c',0x03); ($cnt=0; $cnt<4; $cnt++) { $chr=$str[$cnt]; echo '$str['.$cnt.'] = "'.$str[$cnt].'" = '.sprintf('0x%02x',$chr[0])."\n"; } var_dump(str_split($str));
what this:
$str[0] = "a" = 0x00 $str[1] = "b" = 0x00 $str[2] = "1" = 0x01 $str[3] = "" = 0x00 array(4) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "1" [3]=> string(1) "" }
it seems $chr
string rather character , sprintf()
printing integer value of string - 0 - instead of integer value of single character.
is possible in php? sure there's way...
php not have char (character) type. correct getting 1-character string result.
Comments
Post a Comment