php generate uuid_PHP tutorial

WBOY
Release: 2016-07-13 17:45:10
Original
961 people have browsed it

Java代码 
function create_guid() 

$microTime = microtime(); 
list($a_dec, $a_sec) = explode(" ", $microTime); 
$dec_hex = dechex($a_dec* 1000000); 
$sec_hex = dechex($a_sec); 
ensure_length($dec_hex, 5); 
ensure_length($sec_hex, 6); 
$guid = ""; 
$guid .= $dec_hex; 
$guid .= create_guid_section(3); 
$guid .= '-'; 
$guid .= create_guid_section(4); 
$guid .= '-'; 
$guid .= create_guid_section(4); 
$guid .= '-'; 
$guid .= create_guid_section(4); 
$guid .= '-'; 
$guid .= $sec_hex; 
$guid .= create_guid_section(6); 
return $guid; 

function create_guid_section($characters) 

$return = ""; 
for($i=0; $i<$characters; $i++) 

$return .= dechex(mt_rand(0,15)); 

return $return; 

 
function ensure_length(&$string, $length)   
 
{   
    $strlen = strlen($string);   
   if($strlen < $length)   
   {   
        $string = str_pad($string,$length,"0");   
    }   
     else if($strlen > $length)   
   {   
         $string = substr($string, 0, $length);   
  }   
 
 }   

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478677.htmlTechArticleJava代码 function create_guid() { $microTime = microtime(); list($a_dec, $a_sec) = explode( , $microTime); $dec_hex = dechex($a_dec* 1000000); $sec_hex = dechex($a_sec); ensure_l...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template