YogeshChauhan . com

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.

Syntax


bin2hex ($str)

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

Example


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

//output

596f676573684368617568616e2e636f6d

chr() Function [PHP Version: 4+]

Generate a single-byte string from a number

Syntax


chr(enter_ascii_value)

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;

Example


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

Sources

amazon

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 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

Learn how to use Self JOIN in SQL and MySQLSQL/MySQLWhat is Host Hardening and What are some Important Hardening Steps?MiscA complete guide to add responsive YouTube videos using HTML and CSSCSSHow to modify navigation menus in WordPress?WordPressA quick introduction to API, REST API and PostmanMiscWhat’s a Strict mode in JavaScript?JavaScriptHow JavaScript classes allows us to do less typing (syntactic sugar)?JavaScriptSelector Lists and Combinators in SCSS (Sass)SCSSHow to Create a Backup From Any Database in SQL?SQL/MySQLThe Difference Between isNaN() Method And isNaN() Function In JavaScriptJavaScript4 different Ways to Get JavaScript OutputJavaScriptThe SQL UNION OperatorSQL/MySQL