PHP bin2hex() function with example

PHP bin2hex() function with example

bin2hex() work is a string capacity, it is utilized to change over a given string of ASCII characters to the hexadecimal qualities.

It acknowledges string and returns the hexadecimal changed over the string.

Syntax:

 bin2hex(string);

Examples:

<?php
    $str = "Hello world";
    $hex_str = bin2hex($str);
    
    //printing both strings
    echo ("str = " . $str . "\n");
    echo ("hex_str = " . $hex_str . "\n");
    
    $str = "ABC 123 @#$%. XYZ";
    $hex_str = bin2hex($str);
    
    //printing both strings
    echo ("str = " . $str . "\n");
    echo ("hex_str = " . $hex_str . "\n");    
?>

Code:

<?php
    $str = "Hello world";
    $hex_str = bin2hex($str);
    
    //printing both strings
    echo ("str = " . $str . "\n");
    echo ("hex_str = " . $hex_str . "\n");
    
    $str = "ABC 123 @#$%. XYZ";
    $hex_str = bin2hex($str);
    
    //printing both strings
    echo ("str = " . $str . "\n");
    echo ("hex_str = " . $hex_str . "\n");    
?>

Output:

str = Hello world
hex_str = 48656c6c6f20776f726c64
str = ABC 123 @#$%. XYZ
hex_str = 4142432031323320402324252e2058595a

Recent Posts

error: Alert: Content is protected!!