您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php怎么替换文件后缀

2024/5/15 5:42:08发布24次查看
php替换文件后缀的方法:首先创建一个php示例文件;然后通过“function changetypename($path, $oldtypaname, $newtypename){...}”方法替换文件后缀即可。
本文操作环境: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怎么替换文件后缀的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product