In this tutorial I will show how to use basic PHP functions like md5, trim, ltrim, strtolower, strtoupper, count and array_merge. md5 is an encryption metod that uses a special algorithm which cannot be decrypted. There are some databases with md5 values, but md5 algorithm is just one way. The majority of PHP driven applications, are using md5 passwords to be stored in their databases. How can you use it? If we have a HTML form:
We take the password field as text to see what password we type in this example.
Using POST in first line of code we take the value of password from the HTML form. Then we can encrypt it and check with the entry from our database using a SELECT query. If the result will be empty the password is invalid.
trim() removes the blank spaces from a string. This is very useful also when doing a login or register. There is also ltrim() which can remove blank spaces from left and rtrim() which removes the blank spaces from the right.
Using strlen() we are computing the length of each string after trim(), ltrim() and rtrim() are applied. We can see that the length of $a is 5, length of $b is 4, length of $c is 3 and length of $d is 3, because we applied rtrim and ltrim in the same time using trim. This can remove any blank spaces within your POST value making the application more secure.
strtolower() make small letters from capital ones. strtoupper is the opposite of strtolower().
We can see that $b has now capital letters and $a small letters.
array_merge() allows you to make one single array from one or more.
This will print as one single array. You can see the result wen printing:
Array (  => value1  => value2  => value3  => valure10  => value11  => value12 )
count() is used to see how many elements has an array. You can call use simply by calling :
The output will be 7.
That’s it! Now you know how to use md5 in PHP, strtolower and other useful functions presented from this tutorial.