PHP 和 C#:如何为 Web 内容生成字母数字 ID?

发布于 2024-08-22 05:24:07 字数 269 浏览 3 评论 0原文

我想要一个 PHP 和 C# 脚本,它将生成 id,就像以下网站正在做的那样:

Youtube http://www.youtube.com/watch?v=OdAE3cWlmHw 正在这样做,就像 OdAE3cWlmHw

Bit.ly http://bit.ly/2pUswX 这样做 2pUswX

在 PHP 和 C# 中生成这种类型的唯一 id 的函数是什么?

I want a script in PHP and c# which will generate id's like the following sites are doing:

Youtube http://www.youtube.com/watch?v=OdAE3cWlmHw is doing it like OdAE3cWlmHw

Bit.ly http://bit.ly/2pUswX doing it like 2pUswX

What will be the function to generate such type of unique id's in PHP and c#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以可爱出名 2024-08-29 05:24:07

创建一个包含字符 AZ 和数字 0-9 的数组(或字符串)。然后编写一个循环,运行您想要在 ID 中包含的字符数 - 例如 10 - for ($i = 0; $i < 10; $i++)

在该循环中,获取随机数0 到包含 AZ 的数组/字符串的长度(0-9)之间的数字,查找数组/字符串中该位置的字符并将其附加到您的 ID 字符串中。

PHP 和 C# 的逻辑是相同的,只是语言语法不同。

Create an array (or string) holding the characters A-Z and numbers 0-9. Then write a loop that runs for the number of characters you want in your ID - e.g. 10 - for ($i = 0; $i < 10; $i++)

In that loop, get a random number between 0 and the length of your array/string holding A-Z, 0-9, look up the character at that position in the array/string and append it to your ID string.

This logic is the same for both PHP and C#, just the language syntax will be different.

情何以堪。 2024-08-29 05:24:07

您可以在此处查看一些有关 C# 方面的 codeproject 代码:

http://www.codeproject.com/KB/database/Alphanumaric_incriment.aspx?msg=1983998

如果您熟悉 PHP 和 C#,这将有望回答您的问题。

There is some codeproject code you can take a look at for the C# side of things here:

http://www.codeproject.com/KB/database/Alphanumaric_incriment.aspx?msg=1983998

If you are familiar with both PHP and C#, this will hopefully answer your question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文