ฟังก์ชันที่แปลงสตริงเป็นค่า hexadecimal ทำงานแบบ byte-wise โดยแปลง high nibble ก่อน
รูปแบบ bin2hex()
bin2hex($string)
รับสตริงเข้าไป แปลงเป็นการแทนค่า hexadecimal
ตัวอย่าง
<?php
$my_str1 = "This";
$my_str2 = "is";
$my_str3 = "a";
$my_str4 = "sample";
print(bin2hex($my_str1));
echo "<br>";
print(bin2hex($my_str2));
echo "<br>";
print(bin2hex($my_str3));
echo "<br>";
print(bin2hex($my_str4));
?>
ผลลัพธ์
54686973 6973 61 73616d706c65
เรียก bin2hex กับสตริง 4 ตัว แสดงผลลัพธ์แต่ละบรรทัด This = 54686973, is = 6973, a = 61, sample = 73616d706c65