【发布时间】:2014-05-08 14:42:24
【问题描述】:
我想创建一个具有随机唯一帖子 ID 的帖子,而不是自动增量帖子 ID 我发现对于 Pinterest 中的每个新帖子,它都有一个唯一的 18 位帖子 ID,例如
http://www.pinterest.com/pin/521432463078873423/
这个 18 位数字是什么?创建新帖子时如何在php中生成这个数字?
谢谢!
【问题讨论】:
我想创建一个具有随机唯一帖子 ID 的帖子,而不是自动增量帖子 ID 我发现对于 Pinterest 中的每个新帖子,它都有一个唯一的 18 位帖子 ID,例如
http://www.pinterest.com/pin/521432463078873423/
这个 18 位数字是什么?创建新帖子时如何在php中生成这个数字?
谢谢!
【问题讨论】:
此链接中的第三个选项允许您在创建 GUID 时指定长度。顺便说一句,谷歌充满了“Php 如何创建 GUID”的结果。
http://phpgoogle.blogspot.com/2007/08/four-ways-to-generate-unique-id-by-php.html
<?php
//set the random id length
$random_id_length = 18;
//generate a random id encrypt it and store it in $rnd_id
$rnd_id = crypt(uniqid(rand(),1));
//to remove any slashes that might have come
$rnd_id = strip_tags(stripslashes($rnd_id));
//Removing any . or / and reversing the string
$rnd_id = str_replace(".","",$rnd_id);
$rnd_id = strrev(str_replace("/","",$rnd_id));
//finally I take the first 18 characters from the $rnd_id
$rnd_id = substr($rnd_id,0,$random_id_length);
echo "Random Id: $rnd_id" ;
echo "<br>";
?>
【讨论】:
?post=52143xxxxxxxx?http://www.pinterest.com/pin/521432463078873423/,如何获取帖子ID