php怎么替换文件后缀
2022-12-02 09:01:16
128
{{single.collect_count}}

php替换文件后缀的方法:首先创建一个PHP示例文件;然后通过“function changeTypeName($path, $oldTypaName, $newTypeName){...}”方法替换文件后缀即可。

php入门到就业线上直播课:进入学习
Apipost = Postman + Swagger + Mock + Jmeter 超好用的API调试工具:点击使用

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑

php怎么替换文件后缀?

php 改变文件目录下文件的后缀名

changeTypeName("E:/bak/video/code/views", "html", "phtml"); //改变文件目录下文件的后缀名function changeTypeName($path, $oldTypaName, $newTypeName){$path = "glob://$path/*";$files = new DirectoryIterator($path);foreach ($files as $file) {$fileRealPath = $file->getRealPath(); //文件绝对路径$compressCssFileRealPath = str_replace(".$oldTypaName", ".$newTypeName", $fileRealPath);rename($fileRealPath, $compressCssFileRealPath);}}
登录后复制

相关介绍:

rename() 函数重命名文件或目录。

若成功,则该函数返回 true。若失败,则返回 false。

语法

rename(oldname,newname,context)
登录后复制

参数

oldname必需。规定要重命名的文件或目录。

newname必需。规定文件或目录的新名称。

context可选。规定文件句柄的环境。context 是可修改流的行为的一套选项。

推荐学习:《PHP视频教程

以上就是php怎么替换文件后缀的详细内容,更多请关注php中文网其它相关文章!

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}