【问题标题】:How to generate an unique 18 digit post ID like Pinterest?如何生成像 Pinterest 这样的唯一 18 位帖子 ID?
【发布时间】:2014-05-08 14:42:24
【问题描述】:

我想创建一个具有随机唯一帖子 ID 的帖子,而不是自动增量帖子 ID 我发现对于 Pinterest 中的每个新帖子,它都有一个唯一的 18 位帖子 ID,例如

http://www.pinterest.com/pin/521432463078873423/

这个 18 位数字是什么?创建新帖子时如何在php中生成这个数字?

谢谢!

【问题讨论】:

标签: php unique pinterest


【解决方案1】:

此链接中的第三个选项允许您在创建 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>";

?>

【讨论】:

  • 谢谢,com_create_guid () 应该可以正常工作,如果链接类似于下面的链接而不是?post=52143xxxxxxxx?http://www.pinterest.com/pin/521432463078873423/,如何获取帖子ID
  • 以下是 Pinterest 的实际操作方式:engineering.pinterest.com/blog/…
猜你喜欢
  • 2012-05-02
  • 1970-01-01
  • 2012-08-11
  • 1970-01-01
  • 2017-06-02
  • 2018-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多