標籤:thinkphp源碼學習 to_guid_string函數 hash md5
/**
* 根據PHP各種類型變數產生唯一標識號
* @param mixed $mix 變數
* @return string
*/
function to_guid_string($mix) { if (is_object($mix)) { return spl_object_hash($mix);//spl_object_hash — 返回指定對象的hash id } elseif (is_resource($mix)) {//is_resource — 檢測變數是否為資源類型 $mix = get_resource_type($mix) . strval($mix);//get_resource_type — 返回資源(resource)類型 //strval — 擷取變數的字串值 } else { $mix = serialize($mix);//serialize — 產生一個可儲存的值的表示//$name="津沙港灣" serialize系列化 為s:12:"津沙港灣"; } return md5($mix);//md5 — 計算字串的 MD5 散列值}class Student{ public $name=‘津沙港灣‘;}$stu=new Student();//對象$fp = fopen("d:/wamp/counter.txt","w");//資源$name="津沙港灣";//字串echo to_guid_string($stu);echo "<br/>";echo to_guid_string($fp);echo "<br/>";echo to_guid_string($name);
運行結果為:
00000000411ac22f0000000001dac5a4
7c8337ca66fc7eb79d20461b44630219
99a71c3a715645befef323c9a805f662
本文出自 “11400485” 部落格,請務必保留此出處http://11410485.blog.51cto.com/11400485/1833446
ThinkPHP源碼學習 to_guid_string函數 根據PHP各種類型變數產生唯一標識號