w3resource

PHP: md5_file() function

Description

The md5_file() function is used to calculate the md5 hash ( the hash as a 32-character hexadecimal number ) of a given file.

Version:

(PHP 4 and above)

Syntax:

md5_file(file_name, raw_output)

Parameter:

Name Description Required /
Optional
Type
file_name The file name. Required String
raw_output Refers hex or binary output format, Returns raw 16-bit binary format if raw_output sets TRUE and return 32-bit hex format for setting FALSE (default). Optional Boolean

Return value:

Returns a string on success, FALSE otherwise.

Value Type: String.

Pictorial Presentation

php-string-md5_file()

Example:

<?php
$file_name = 'testvf.txt';
echo md5_file($file_name);
?>

Output:

f006da995a5475841a21f546be8e4f11 

View the example in the browser

See also

PHP Function Reference

Previous: ltrim
Next: md5



PHP: Tips of the Day

PHP: Using str_replace so that it only acts on the first match?

Can be done with preg_replace:

function str_replace_first($from, $to, $content)
{
    $from = '/'.preg_quote($from, '/').'/';

    return preg_replace($from, $to, $content, 1);
}

echo str_replace_first('abc', '123', 'abcdef abcdef abcdef'); 
// outputs '123def abcdef abcdef'

The magic is in the optional fourth parameter [Limit]. From the documentation:

[Limit] - The maximum possible replacements for each pattern in each subject string. Defaults to -1 (no limit).

Ref : https://bit.ly/35SCuP8