Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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
Blueimp上载php脚本更改preg_replace_回调正则表达式_Php_Regex_Blueimp - Fatal编程技术网

Blueimp上载php脚本更改preg_replace_回调正则表达式

Blueimp上载php脚本更改preg_replace_回调正则表达式,php,regex,blueimp,Php,Regex,Blueimp,我想在upcount_name函数中更改此正则表达式: protected function upcount_name_callback($matches) { $index = isset($matches[1]) ? intval($matches[1]) + 1 : 1; $ext = isset($matches[2]) ? $matches[2] : ''; return ' ('.$index.')'.$ext; } protected function u

我想在upcount_name函数中更改此正则表达式:

protected function upcount_name_callback($matches) {
    $index = isset($matches[1]) ? intval($matches[1]) + 1 : 1;
    $ext = isset($matches[2]) ? $matches[2] : '';
    return ' ('.$index.')'.$ext;
}

protected function upcount_name($name) {
    return preg_replace_callback('/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/', 
    array($this, 'upcount_name_callback'),$name,1);
}
从blueimp上传脚本。 此脚本更改名称以获得唯一的文件名,如“image(1).jpg”,“image(2),jpg”等…(请注意括号内的基本名称和数字之间的空格)


现在我想返回“image-1.jpg”、“image-2.jpg”。

如果这就是您想要的,只需更改返回行,如下所示

 protected function upcount_name_callback($matches) {
        $index = isset($matches[1]) ? intval($matches[1]) + 1 : 1;
        $ext = isset($matches[2]) ? $matches[2] : '';
        return '-'.$index.'.$ext; // replaced this return ' ('.$index.')'.$ext;
    }

protected function upcount_name($name) {
    return preg_replace_callback('/(?:(?: \(([\d]+)\))?(\.[^.]+))?$/', 
    array($this, 'upcount_name_callback'),$name,1);
}

你是说你有像“image-1.jpg”、“image-2.jpg”这样的独特文件吗?如果是这样,我认为您可以将正则表达式更改为相同的行为(但与该格式匹配),如下所示:

return preg_replace_callback('/(?:(?:-([\d]+))?(\.[^.]+))?$/'

但是我可能完全误解了。

这里的超级家伙,发布了解决方案,但是他的答案被删除了,所以我在这里发布了感谢超级家伙的帖子

/(?:(?:-([\d]+))?(\.[^.]+))?$/

哦,我想我完全误解了这个问题。我的错…我的英语…我的匆忙。谢谢你。很高兴答案有用