- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How does the bin2hex() function work in PHP?
It is a function that helps in converting a string into a hexadecimal value. It is done byte wise and the high nibbled bytes are converted first.
Syntax of bin2hex() function
bin2hex($string)
It takes in a string and converts the string to a hexadecimal representation.
Example
<?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)); ?>
Output
54686973 6973 61 73616d706c65
Within the <php> tags, the bin2hex function is called on 4 elements which are previously defined. Then, the result of calling the bin2hex function on each of the string is displayed on the console.
Advertisements