Convert "Hello world!" to a hexadecimal value:
<?php $str = Bin2Hex ("Hello world!"); Echo ($STR);?>
Definition and usage
The Bin2Hex () function converts a string of ASCII characters to a hexadecimal value. Strings can be converted back by using the pack () function.
Grammar
Bin2Hex (String)
Parameter description
string is required. Specifies the string to convert.
Technical details return value:
Returns the hexadecimal value of the string to be converted.
Convert a string value from binary to 16 and back again:
<?php$str = "Hello world!"; echo Bin2Hex ($STR). "<br>"; Echo Pack ("h*", Bin2Hex ($STR)). "<br>";? >
PHP has the Bin2Hex method, but there is no Hex2bin method, the following simple implementation hex2bin: <?phpfunction Hex2bin ($data) { $len = strlen ($data); Return Pack ("H". $len, $data); }?>
The function of PHP Bin2Hex () is to convert a string of ASCII characters to a hexadecimal value.
Bin2Hex Definition and usage
The AddAttribute () function adds an attribute to the SimpleXML element.
The function has no return value.
Grammar
Class simplexmlelement{string AddAttribute (Name,value,ns)}
Parameter description
Name is required. The name of the specified property.
Value is required. The value of the specified property.
NS is optional. Specifies the namespace of the attribute.
Bin2Hex instances
XML file:
<?xml version= "1.0" encoding= "iso-8859-1"? ><note><to>george</to><from>john</ From>
PHP Code:
<?php$xml = simplexml_load_file ("Test.xml"), $xml->body[0]->addattribute ("type", "small"); foreach ($xml- >body[0]->attributes () as $a + $b) { echo $a, ' = ' ', $b, ' '; }? >
Output:
Type= "Small"