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
Php 用新名称替换URL文件名_Php_File Io - Fatal编程技术网

Php 用新名称替换URL文件名

Php 用新名称替换URL文件名,php,file-io,Php,File Io,我想用新修改的文件名替换URL文件名 $url = 'http://p1.pichost.me/i/53/1770973.jpg'; $old_file_name = basename($fullBasePath); $new_file_name = old_file_name_modified; $fileName = renameUrl($url, old_file_name, new_file_name); 我检查了,但它不支持url。是否有其他php函数可用于此操作。您可以使用来反构造

我想用新修改的文件名替换URL文件名

$url = 'http://p1.pichost.me/i/53/1770973.jpg';
$old_file_name = basename($fullBasePath);
$new_file_name = old_file_name_modified;
$fileName = renameUrl($url, old_file_name, new_file_name);
我检查了,但它不支持url。是否有其他php函数可用于此操作。

您可以使用来反构造URL,然后使用来重新构造它

例如:

$parts = parse_url($url);
$parts['path'] = urlencode($parts['path']);
$newurl = http_build_url($parts);
试试这个

$url = 'http://p1.pichost.me/i/53/1770973.jpg';
$old_file_name = basename($fullBasePath);
$new_file_name = old_file_name_modified;
$fileName = str_replace($old_file_name, $new_file_name, $url);

我不知道你想在这里实现什么?您正在尝试通过HTTP重命名远程文件吗?我的url中有文件名,空格
http://p1.pichost.me/i/53/1770973 name.jpg
。。。使用
rawurlencode('http://p1.pichost.me/i/53/1770973 name.jpg')
,它与
/
一起对整个过程进行编码,因此我尝试使用
basename($fullBasePath)获取$filename
并使用rawurlencode($fullBasePath)对其进行编码,然后重命名url文件名