PHP String Functions Series Part 2
bin2hex() Function [PHP Version: 4+]
Converts binary data into hexadecimal representation.
Returns an ASCII string containing the hexadecimal representation of str. The conversion is done byte-wise with the high-nibble first.
Syntax
bin2hex ($str)
where str = the string to be converted, it’s required
Example
$str = bin2hex("YogeshChauhan.com");
echo($str);
//output
596f676573684368617568616e2e636f6d
chr() Function [PHP Version: 4+]
Generate a single-byte string from a number
Syntax
chr(enter_ascii_value)
Returns a one-character string containing the character specified by interpreting bytevalue as an unsigned integer.
bytevalue: An integer between 0 and 255.
Values outside the valid range (0..255) will be bitwise and’ed with 255, which is equivalent to the following algorithm:
while ($bytevalue < 0) {
$bytevalue += 256;
}
$bytevalue %= 256;
Example
$str = chr(046);
echo $str; // &
Sources
ASCII bin2hex chr functions string