让我说我检查一下
$strig = "red-hot-chili-peppers-californication";
已存在于我的数据库中:
$query = dbquery("SELECT * FROM `videos` WHERE `slug` = '".$strig."';");
$checkvideo = dbrows($query);
if($checkvideo == 1){
// the code to be executed to rename $strig
// to "red-hot-chili-peppers-californication-2"
// it would be great to work even if $string is defined as 
// "red-hot-chili-peppers-californication-2"  and 
// rename $string to "red-hot-chili-peppers-californication-3"  and so on...
}
我想这样做是为了更友好的网址结构创建独特的slu ..
谢谢.
我可以为您提供Codeigniter increment_string()功能的来源:
/**
 * CodeIgniter String Helpers
 *
 * @package     CodeIgniter
 * @subpackage  Helpers
 * @category    Helpers
 * @author      ExpressionEngine Dev Team
 * @link        http://codeigniter.com/user_guide/helpers/string_helper.html
 */
/**
 * Add's _1 to a string or increment the ending number to allow _2, _3, etc
 *
 * @param   string  $str  required
 * @param   string  $separator  What should the duplicate number be appended with
 * @param   string  $first  Which number should be used for the first dupe increment
 * @return  string
 */
function increment_string($str, $separator = '_', $first = 1)
{
    preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);
    return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first;
}
通过向其附加数字或增加数字来增加字符串.用于创建"副本"或文件或复制具有唯一标题或slu g的数据库内容.
用法示例:
Run Code Online (Sandbox Code Playgroud)echo increment_string('file', '_'); // "file_1" echo increment_string('file', '-', 2); // "file-2" echo increment_string('file-4'); // "file-5"
| 归档时间: | 
 | 
| 查看次数: | 1971 次 | 
| 最近记录: |