Php custom hash function instance, phphash function _ PHP Tutorial

Source: Internet
Author: User
Php custom hash function instance and phphash function. Php custom hash function example. phphash function this article describes the php custom hash function implementation method. Share it with you for your reference. The specific analysis is as follows: the php user-defined hash function instance implemented by php and the phphash function are demonstrated here.

This example describes how to implement the php custom hash function. Share it with you for your reference. The specific analysis is as follows:

A simple hash algorithm implemented by php can be used for encryption. However, this function is too simple to be used for decryption.

function SimpleHash($str){    $n = 0;  // The magic happens here:  // I just loop trough all letters and add the  // ASCII value to a integer variable.   for ($c=0; $c < strlen($str); $c++)    $n += ord($str[$c]);  // After we went trough all letters  // we have a number that represents the  // content of the string  return $n;}

Call method:

$TestString = 'www.jb51.net';print SimpleHash($TestString); // returns: 1082

I hope this article will help you with php programming.

Examples in this article describes how to implement php custom hash functions. Share it with you for your reference. The specific analysis is as follows: the php implementation is demonstrated here...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.