如何生成像wordpress一样独特的标题?

发布于 2024-08-31 22:35:50 字数 126 浏览 3 评论 0原文

我是玛雅人, 我需要生成像 wordpress 这样的独特标题。 如果标题 hello-world 存在,下一个标题将是 hello-world-2

谢谢

hye im maya,
i need to generate unique title like wordpress.
if title hello-world is exist,the next title will be hello-world-2

thanks

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

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

发布评论

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

评论(1

请你别敷衍 2024-09-07 22:35:50
  1. 检查服务器以查看该标题是否已存在

  2. 如果存在,请附加 -2 并转到步骤 1如果您已附加 -2 并且标题已存在,请将其替换为 -3,依此类推。

  3. 如果没有,请插入该文件。

步骤 1 的示例:

MySQL:

SELECT `title` FROM `table` WHERE `title` = '{$title}';

文件 (PHP):

$exists = file_exists("path/to/file");

步骤 2 的示例:

$iteration = 2;
while($exists){ 

      $newname = $file . '-' . $iteration;
      $iteration++;
      // Check to see if the file exists here

}
else{
    // Add the file here
}
  1. Check the server to see if that title already exists

  2. If it does, append a -2 and go to step 1. If you have already appended a -2 and the title already exists, replace it with a -3, and so on.

  3. If it doesn't, insert the file.

Example for step 1:

MySQL:

SELECT `title` FROM `table` WHERE `title` = '{$title}';

File (PHP):

$exists = file_exists("path/to/file");

Example for Step 2:

$iteration = 2;
while($exists){ 

      $newname = $file . '-' . $iteration;
      $iteration++;
      // Check to see if the file exists here

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