How to get a hex dump of a string in PHP

2 Answers

0 votes
$s = "php pro";

echo bin2hex($s);


   
   
/*
run:
    
7068702070726f
    
*/

 



answered Dec 29, 2021 by avibootz
0 votes
$s = "php pro";

for ($i = 0; $i < strlen($s); $i++) {
    echo str_pad(dechex(ord($s[$i])), 2, '0', STR_PAD_LEFT) . ' ';
}



   
   
/*
run:
    
70 68 70 20 70 72 6f 
    
*/

 



answered Dec 29, 2021 by avibootz

Related questions

2 answers 93 views
2 answers 112 views
2 answers 210 views
1 answer 143 views
143 views asked Aug 2, 2015 by avibootz
1 answer 94 views
2 answers 152 views
...