Yogesh Chauhan's Blog

bin2hex() and chr() String Functions in PHP

in PHP on July 6, 2020

PHP String Functions Series Part 2

bin2hex() Function [PHP Version: 4+]

Converts binary data into hexadecimal representation.

Returns an ASCII string containing the hexadecimal representation of str. The conversion is done byte-wise with the high-nibble first.


bin2hex ($str)

where str = the string to be converted, it’s required


$str = bin2hex("YogeshChauhan.com");



chr() Function [PHP Version: 4+]

Generate a single-byte string from a number



Returns a one-character string containing the character specified by interpreting bytevalue as an unsigned integer.

bytevalue: An integer between 0 and 255.

Values outside the valid range (0..255) will be bitwise and’ed with 255, which is equivalent to the following algorithm:

while ($bytevalue < 0) {
    $bytevalue += 256;
$bytevalue %= 256;


$str = chr(046);
echo $str; // &


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
What is ECMAScript?JavaScriptHow to change the style for checked radio button or checkboxes using CSS?CSSHow to remove trailing characters from a string using JavaScript?JavaScriptHow to use data-* Attributes in HTML?HTMLHow to CREATE TABLE in SQL with and without using Another Table?SQL/MySQLHow to add transparent text on top of an image using CSS?CSS@forward modules with a prefix in SCSS (Sass)SCSSHow to Draw a Text Image using JavaScript?JavaScriptSELF JOIN in PostgresPostgresHow to install Gulp with WordPress?WordPress3 Types of Arrays in PHPPHPHow to get front page or home page ID in WordPress?WordPress