Home » PHP

PHP bin2hex() function with example

PHP bin2hex() function: Here, we are going to learn about the bin2hex() function with example in PHP.
Submitted by IncludeHelp, on February 03, 2019

PHP bin2hex() function

bin2hex() function is a string function, it is used to convert a given string of ASCII characters to the hexadecimal values.

It accepts string and returns the hexadecimal converted string.

Syntax:

    bin2hex(string);

Examples:

    Input:
    str = Hello world
    Output:
    hex_str = 48656c6c6f20776f726c64

    Input:
    str = ABC 123 @#$%. XYZ
    Output:
    hex_str = 4142432031323320402324252e2058595a

PHP 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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.