How to replace file suffix in php

藏色散人
Release: 2023-03-10 20:34:01
Original
3023 people have browsed it

php method to replace file suffix: first create a PHP sample file; then replace the file suffix through the "function changeTypeName($path, $oldTypaName, $newTypeName){...}" method.

How to replace file suffix in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to replace the file suffix with php?

php Change the suffix name of the file in the file directory

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); } }
Copy after login

Related introduction:

rename() function renames the file or directory.

If successful, the function returns true. On failure, returns false.

Syntax

rename(oldname,newname,context)
Copy after login

Parameters

oldname Required. Specifies the file or directory to be renamed.

newname Required. Specifies the new name of the file or directory.

context Optional. Specifies the environment for a file handle. context is a set of options that modify the behavior of the stream.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to replace file suffix in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!