Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何生成像wordpress这样的唯一标题?_Php_Wordpress_Stub - Fatal编程技术网

Php 如何生成像wordpress这样的唯一标题?

Php 如何生成像wordpress这样的唯一标题?,php,wordpress,stub,Php,Wordpress,Stub,惠因玛雅, 我需要生成像wordpress这样的唯一标题。 如果titlehello-world存在,则下一个标题将是hello-world-2 谢谢 检查服务器以查看该标题是否已存在 如果是,请附加一个-2并转至步骤1。如果您已经添加了-2,并且标题已经存在,请将其替换为-3,依此类推 如果没有,请插入该文件 步骤1的示例: MySQL: SELECT `title` FROM `table` WHERE `title` = '{$title}'; 文件(PHP): 步骤2的示例: $ite

惠因玛雅, 我需要生成像wordpress这样的唯一标题。 如果titlehello-world存在,则下一个标题将是hello-world-2

谢谢

  • 检查服务器以查看该标题是否已存在

  • 如果是,请附加一个
    -2
    并转至步骤1。如果您已经添加了
    -2
    ,并且标题已经存在,请将其替换为
    -3
    ,依此类推

  • 如果没有,请插入该文件

  • 步骤1的示例:

    MySQL:

    SELECT `title` FROM `table` WHERE `title` = '{$title}';
    
    文件(PHP):

    步骤2的示例:

    $iteration = 2;
    while($exists){ 
    
          $newname = $file . '-' . $iteration;
          $iteration++;
          // Check to see if the file exists here
    
    }
    else{
        // Add the file here
    }
    

    这似乎很简单,你想要什么语言?你所要做的就是检查数据库中是否存在该名称,如果它确实存在,则检查末尾是否有数字,如果是,则在数字中添加一个数字并将其作为标题,否则在标题中添加“-2”。Pfft,为什么要使用有意义的标题?只需添加一天中的时间,并使用一个完美的没有冲突的摘要函数,然后使用它:-P
    $iteration = 2;
    while($exists){ 
    
          $newname = $file . '-' . $iteration;
          $iteration++;
          // Check to see if the file exists here
    
    }
    else{
        // Add the file here
    }