PHP Tutorial #14 String Methods (Md5_File, Md5, Nl2br and Addcslaches )

in utopian-io •  21 days ago

Image Source

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

Proof of Work Done 

https://github.com/alexendre-maxim/PHP-Tutorial/blob/master/str4.php

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Happy New Year @alexendre-maxim

Thank you for your contribution to the video tutorial.

I can see that your recent video tutorials have improved in your presentations and that you have put effort in your delivery.

You are also speaking slower and more deliberate in your speech.

You can try to pay more special attention to certain words.

Eg. In the beginning you mentioned about 'heading', so I knew you were talking about 'heading', but when I listened to your audio, I heard 'hidden' instead of 'heading'.

Heading and hidden are different as the vowel sound of 'heading' is a short "e", whereas the "i' in hidden is a short 'i' sound.

My students who are learning English as a second language has that difficulty also. They can't distinguish between a short i sound from a short e sound.

So you can pay careful attention to the vowel sounds in the pronunciation.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

·

Thank you for your review, @rosatravels! Keep up the good work!

Hi @alexendre-maxim!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @alexendre-maxim!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations @alexendre-maxim! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!