Repository
https://github.com/php/php-src
What Will I Learn?
I will learn the string methods this is the fourth part , we will take the " Md5_File, Md5, Nl2br and Addcslaches " methods.
- What's the " Md5_File " method and how to use it.
- How to crypt a string using " Md5 " method.
- What's the " Nl2br " method and their uses.
- How to add slashes before predefined characters using " Addslashes " method.
Requirements
- Server support PHP , Xampp or Wamp for example
- An IDE like Sublime text.
- Browser (Chrome for example)
Difficulty
- Basic
Description
1- Md5_File Method
The md5_file method calculates the MD5 of the filename file using the RSA Data Security algorithm, and then returns the calculated value. The result is a number of 32 hexadecimal characters.
It has two parameters :
- The first parameter is the file :
which is the file to calculate.
- The second parameter is the format :
It's optional, specifies the format, when TRUE, returns the pretreatment in raw binary format with a size of 16.
- TRUE- the binary format of 16 characters .
- FALSE - Default. The binary format of 32 characters .
This parameter was added in PHP 5.0 .
To use the md5_file we need to pass the file as parameter
md5_file($file, format);
I have a " txt " file named " utopian " I want to hash the content in this file using the " md5_file " method
echo "<h3>md5_file Method</h3>";
echo md5_file("utopian.txt");
The md5_file will return a string of md5 , you can replace the content of the file by the result of the md5_file , I will print the result
2- Md5 Method
The md5 method returns the md5 of the string, as a hexadecimal number of 32 characters. The md5 function calculates the MD5 of the character string using the RSA Data Security algorithm, and returns the result.
It has two parameters :
- The first parameter is the string
- The second is the cript :
It's optional. By default it is false. If the optional cript parameter is set to TRUE, then the md5 is returned in raw binary format with a length of 16.
- True - the binary format cript of 16 characters
- False- Default. spell number of 32 characters .
This parameter was added in PHP 5.0 .
To use the md5 method we need to pass the string as parameter
md5($string, format);
I have a string and I want to hash it using md5 method
echo "<h3>md5 Method</h3>";
$string = "I love utopian !";
echo md5($string);
The md5 will return a string of 32 characters , this is the result
3- Nl2br Method
The nl2br method returns string after inserting "<br>" or "</br>" tags in front of all new lines.
It has the string as parameter which is the string to process.
To use the nl2br method we need to pass the string as parameter
nl2br($string);
The browser will ignore all new lines , and to be sensitive we need to use the nl2br method
$string2 = "
1- PHP is the best !
2- I love utopian !
";
We have 2 points , if we print directly this string without the nl2br method the browser will ignore the lines
4 - Addcslaches Method
The addcslaches Method Returns string, after adding backslashes in front of any characters that are in the charlist.
It has two parameters :
- The first is the string : specifies the string to escape
- The second parameter is the charlist :
Specifies the characters or range of characters to be assigned by addcslashes .
Pay attention to the use of characters such as 0, a, b, f, n, r, t and v. They will be converted to \ 0, \ a, \ b, \ f, \ n, \ r, \ t and \ v.
In PHP, \ 0 (NULL), \ r (carriage return), \ n (new line), \ v (horizontal tab) and \ t (tab) are predefined as escape sequences.
To use the addcslaches we need to pass two parameters , the string and the charlist
addcslaches($string , charlist);
I have a string and I want to insert slaches before some characters
echo "<h3>addcslashes Method</h3>";
echo addcslashes($string2, 'ei');
The method will add slaches before the letters " e " and " i "
Video Tutorial
Curriculum
- PHP Tutorial #01 Indexed Arrays, Associative Arrays and Multidimensional Arrays
- PHP Tutorial #02 Array Methods (Sort, Rsort, Ksort, Krsort , Array_Reverse And Shuffle)
- PHP Tutorial #03 Array Methods ( Search Methods , Addition Methods and the Remove Methods)
- PHP Tutorial #04 Array Methods (Array_Sum, Array_Rand, Array_Column and Array_Unique)
- PHP Tutorial #05 Array Methods (Array_Chunk, Array_Combine, Array_Count_Values and Array_Product)
- PHP Tutorial #06 Array Methods (Array_Fill_Keys,Array_Fill, Array_Flip and Array_Filter)
- PHP Tutorial #07 Array Methods ( Array_Keys, Array_Map, Array_Merge and Array_Pad )
- PHP Tutorial #08 Array Methods ( Array_Replace, Array_Values, Array_Slice and Array_Intersect )
- PHP Tutorial #09 Array Methods (Array_Walk, Current, Next, Prev, End and Reset )
- PHP Tutorial #10 Array Methods (Array_Diff_Key, Array_Diff, Array_Intersect_Key and Array_Change_Key_Case )
- PHP Tutorial #11 String Methods ( Addslaches, Chr, Chop and Chunk_splite )
- PHP Tutorial #12 String Methods ( Bin2Hex, Count_Chars, Explode and Hex2Bin )
- PHP Tutorial #13 String Methods (Implode, Join, Lcfirst, Ltrim and Fprintf )
Proof of Work Done
https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/str4.php