X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

PHP bin2hex() Function

PHP String Reference PHP String Reference

Example

Convert "Hello World!" to hexadecimal values:

<?php
$str = bin2hex("Hello World!");
echo($str);
?>

Run example »

Definition and Usage

The bin2hex() function converts a string of ASCII characters to hexadecimal values. The string can be converted back using the pack() function.


Syntax

bin2hex(string)

Parameter Description
string Required. The string to be converted

Technical Details

Return Value: Returns the hexadecimal value of the converted string
PHP Version: 4+


More Examples

Example 1

Convert a string value from binary to hex and back:

<?php
$str = "Hello world!";
echo bin2hex($str) . "<br>";
echo pack("H*",bin2hex($str)) . "<br>";
?>

Run example »


PHP String Reference PHP String Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook