https://github.com/php/php-src
I will learn the string methods the second part we will take the " Bin2Hex, Count_Chars, Explode and Hex2Bin " methods
The bin2hex function converts the binary representation data to hexadecimal representation. The bin2hex function returns a text string encoding ASCII that contains hexadecimal representation of the string parameter.
It has " The String " as parameter and it returns the hexadecimal representation of the entered text string.
To use the Bin2Hex method you need to pass the string as parameter
bin2hex($string)
In this example I will convert a string " PHP is the best ! " to the Hexadecimal representation using " Bin2Hex " method
$str = "PHP is the best !";
$b2x = bin2hex($str);
echo "PHP is the best ! in HEX : " . $b2x;
I created a variable " b2x " to contain the returning value from the method and I passed the string as parameter , this is the result
The count_chars function returns information about the characters in the text string. The function returns the number of iterations for each byte-value from the value 0 to 255 in a text string in different ways.
It has the string as parameter and it returns 4 results depending on the number that you give as parameter.
To use the count_chars method you must pass the string and the num as parameters
count_chars($string, num)
The method returns 4 results depending to the num passed as parameter , for example if the " num " equals to 1 it will return an array with ASCII code of values exist in the string passed as parameter, also if the " num " equals to 3 it will return a string with all the letters used in the string .
The explode function divides a text string into sections and returns it as an array. The explode function returns an array of text strings. Each text string is a segmentation of the total text string by dividing it at the delimiter string.
It has 3 parameters :
To use the explode method you pass the delimiter and the string as parameters
explode(delimiter,$string)
I will use the same string " PHP is the best ! " as parameter to the explode method , it will return an indexed array starts from 0 to the number of the last element.
print_r(explode(" ", $str));
The delimiter is the space , the explode method will cut the element before the space and add it to the array , finally it will return the indexed array
The hex2bin function decodes the hexadecimal encoding of the binary representation strings. The hex2bin function does not convert the hexadecimal representation of numbers to binary representation, but uses the base_convert () function to perform such a transformation.
It has " the data " as parameter and it returns the binary representation of the entered data, or the FALSE value in case of failure.
The hex2bin function causes the error E_WARNING if the length of the text string is odd or has a hexadecimal representation.
To use the Hex2Bin method you must pass the string as parameter
hex2bin($string)
I will use the " b2x " variable that I have created in the previous example to convert it from the hexadecimal representation to the binary
echo hex2bin($b2x);
The function will return a binary data from the hexadecimal representation and this is the result
https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/str2.php