How to display the file extension? Implementation code for batch replacement of file names in PHP

WBOY
Release: 2016-07-29 08:46:16
Original
1045 people have browsed it

The code is as follows

Copy the codeThe code is as follows:


$dir = 'D:Program FilesresourceapplicationSkinPNG\';//Pay attention to the path here, add two at the end, the first one means change, but it is easy this way When encountering other specific escapes, you need to make careful judgments. You can write it as follows
$dir = 'D:/Program Files/resource/application/Skin/PNG/';//Writing a path like this, you don’t have to worry about escaping Problem. Don’t leave out the last one
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if ($file != ". " && $file != "..")
{
if(filetype($dir . $file) == 'file')
{
$newfile = str_replace(array('_PNG','_XML','_ICO '),array('.PNG','.XML','.ICO'), $file);
var_dump($file.' =======> '.$newfile.'
');
rename($dir . $file, $dir . $newfile);
}
}
}
closedir($dh);
}

The above introduces how to display file extensions and the implementation code for batch replacement of file names in PHP, including how to display file extensions. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template