bin2hex() function in PHP

PHPProgrammingServer Side Programming

The bin2hex() function is used to convert primary data to hexadecimal representation

Syntax

bin2hex(str)

Parameters

  • str − The string to be converted.

Return

The bin2hex() function converts a string of ASCII characters to hexadecimal values.

The following is an example −

Example

Live Demo

<?php
   $s = bin2hex("Welcome!");
   echo($s); 
?>

The following is the output −

Output

57656c636f6d6521

Let us see another example −

Example

Live Demo

<?php
   $val = bin2hex("1011");
   echo($val); 
?>

The following is the output −

Output

31303131
raja
Published on 16-Oct-2018 12:55:50
Advertisements