Categories: PHP

sha1 – PHP String Functions

Syntax :

sha1 ( string, raw_output );

Description :

sha1() function calculates the sha1 hash of a string.


Parameter :

[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|lef|lef|left”]
Name, Required /Optional, Value Type, Description
string , Required, String , The file for which hash is to be calculated.
raw_output, Optional, boolen, A boolean value that specifies hex or binary output format:
,,If TRUE, Raw 20 character binary format data will be returned.
,,If FALSE, Default 40 character hex number will be returned.

[/table]


Output :

This function returns the string, calculated for SHA-1 hash as a string.


ChangeLog :

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, Description
PHP 5.1.0 , Changed the function to use the streams API. It means that you can use it with wrappers like sha1_file(‘http://www.tutorialmines.net/..’)
[/table]


Related articles :  md5(), sha1_file(), crc32(), md5_file(), crypt().


sha1() – PHP Functions Example 1 :
<?php
$strExample = 'tutorialmines.net';
echo "\n".sha1($strExample);
if (sha1($strExample) === 'fd4d899c9d520b0569dca7a67c1c5293c36d2400') {
    echo "\nWould you like to have php tutorial or html?";
}
$strExample = "Hi"; 
echo "\nThe string: ".$strExample."\n"; 
echo "TRUE - Raw 20 character binary format: ".sha1($strExample, TRUE)."\n"; 
echo "FALSE - 40 character hex number: ".sha1($strExample)."\n"; 
?>

Output of above code in the browser is as below:

fd4d899c9d520b0569dca7a67c1c5293c36d2400
Would you like to have php tutorial or html?
The string: Hi
TRUE – Raw 20 character binary format: ”ÝžÁ)Dž÷òVè/¾0æÑ®@
FALSE – 40 character hex number: 94dd9e08c129c785f7f256e82fbe0a30e6d1ae40

jyoti rani

Recent Posts

Modern Toys, Magical Moments: Why the Best Toy Shop in Noida Is More Than Just a Store

When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…

6 months ago

Rediscovering Joy: A New Era of Creativity & Comfort in Toy Stores

In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…

6 months ago

Unboxing Imagination: Discovering the Joy of Play at a Toy Store in Noida

In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…

6 months ago

Imagination Unboxed: Discover Joy at the Toy Shop in Delhi

In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…

6 months ago

Play with Purpose: Discovering the Ultimate Toy Store in Noida

When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…

6 months ago

From Tears to Toys: Exploring Modern Childhood through Delhi’s Favorite Toy Shop

In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…

6 months ago