Introduction
In this article I describe the PHP string functions md5, md5_file and metaphone. To learn some other math functions, go to:
- String Functions in PHP: Part1
- String Functions in PHP:Part2
- String Functions in PHP:Part3
- String Functions in PHP:Part4
- String Functions in PHP:Part5
- String Functions in PHP:Part6
- String Functions in PHP:Part7
- String Functions in PHP:Part8
PHP md5() Function
The PHP string md5 function calculates the md5 of a string and returns it as as a 32-character hexadecimal number or optionally in raw binary format with a length of 16.
Syntax
Parameter in md5 Function
The parameters of the md5 function are:
Parameter |
Description |
string |
It specifies the string to be calculated. |
raw |
It specifies hex or binary output.
- TRUE - Raw 16 character binary format.
- FALSE - Default. 32 character hex number.
|
Example
An example of the md5 function is:
<?php
$str="Mcn Solution";
echo "".$str."</br>";
echo md5($str);
?>
Output
PHP md5_file() Function
The PHP string md5_file function calculates the md5 of the specified file and returns a string on success or false on failure.
Syntax
Parameters in md5_file Function
The parameters of the md5_file function are:
Parameter |
Description |
string |
It specifies the string to be calculated. |
raw |
It specifies hex or binary output.
- TRUE - Raw 16 character binary format.
- FALSE - Default. 32 character hex number.
|
Example
An example of the md5_file function is:
<?php
$filename="ltrim.php";
echo md5_file($filename);
?>
Output
PHP metaphone() Function
The PHP string metaphone function calculates the metaphone key of the string and returns the metaphone key on success or false on failure. A metaphone key is like a soundex key except a metaphone key is more accurate for English.
Syntax
metaphone( string, length) |
Parameter in metaphone Function
The parameters of the metaphone function are:
Parameter |
Description |
string |
It specifies the string to check. |
length |
It specifies the maximum length of the metaphone key. |
Example
An example of the metaphone function is:
<?php
echo metaphone("MCN");
?>
Output