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 227 views
2 answers 262 views
2 answers 333 views
1 answer 236 views
236 views asked Aug 2, 2015 by avibootz
1 answer 221 views
2 answers 274 views
...