String Functions in PHP: Part 9

Introduction

In this article I describe the PHP string functions md5, md5_file and metaphone. To learn some other math functions, go to:

  1. String Functions in PHP: Part1
     
  2. String Functions in PHP:Part2
     
  3. String Functions in PHP:Part3
     
  4. String Functions in PHP:Part4
     
  5. String Functions in PHP:Part5
     
  6. String Functions in PHP:Part6
     
  7. String Functions in PHP:Part7
     
  8. 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

md5(string, raw)

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

md5-string-function-in-php.jpg
 

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

md5_file(string, raw)

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

md5-file-string-function-in-php.jpg 

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

metaphone-string-function-in-php.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all