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 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to create a simple slider with CSS and jQuery?CSSHow to make HTML form interactive and using CSS?CSSHow to change CSS with JavaScript?CSSHow to add CurrencyPipe in TypeScript file in Angular 9 Project?AngularSolution to “Call to undefined function mysql_error()” in RevSlider WordPress PluginWordPressJavaScript Number MethodsJavaScriptThe flex-grow, flex-shrink and flex-basis Properties in CSSCSSHow to clean up after a plugin uninstall in WordPress?WordPressThe SELECT DISTINCT Statement in SQLSQL/MySQLHow to get start index and end index (as int) of substring in Swift?SwiftDebugging in WordPress Part 1: WP_DEBUGWordPressHow to verify your domain in Google Console with a TXT record?Miscellaneous