thinkphp Source Learning to_guid_string function generates a unique identification number based on PHP various types of variables

Source: Internet
Author: User

/**
* Generate unique identification numbers based on PHP various types of variables
* @param mixed $mix variables
* @return String
*/

Function to_guid_string ($mix)  {    if  (Is_object ($mix))  {         return spl_object_hash ($mix);//spl_object_hash -  Returns the hash id     } elseif  (Is_resource ($mix)) of the specified object  {//is_resource  -  detects if a variable is a resource type           $mix  = get_resource_ Type ($mix)  . strval ($mix);//get_resource_type -  return resource (Resource) types  //strval -   Get the string value of a variable     } else {         $mix  = serialize ($mix);//serialize -  produces a representation of a stored value//$name = "Jin Sha Wan"   serialize series   For s:12: "Jin Sha Harbor";     }    return md5 ($mix);//md5 -  computes the string  MD5  hash value}class student{    public  $name = ' Jin Sha harbour ';} $stu =new student ();//Object $fp = fopen ("D:/wamP/counter.txt "," w ");//Resources $name=" Jin Sha Harbor ";//String echo to_guid_string ($stu);echo " <br/> "; echo to_ Guid_string ($fp);echo  "<br/>"; echo to_guid_string ($name);


The result of the operation is:

00000000411ac22f0000000001dac5a4
7c8337ca66fc7eb79d20461b44630219
99a71c3a715645befef323c9a805f662

This article is from the "11400485" blog, please be sure to keep this source http://11410485.blog.51cto.com/11400485/1833446

thinkphp Source Learning to_guid_string function generates a unique identification number based on PHP various types of variables

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.