<?php
//Rename files and remove spaces, commas, equal signs, semi-colons, apostrophes, etc.:
//foreach(glob("{*.amr,*.AMR,*.mp3,*.MP3}",GLOB_BRACE ) as $file) {
foreach(glob("{*.png}",GLOB_BRACE ) as $file) {
if (strpos($file, " ") > 0) { //If there are more than 0 spaces in the name.
$x = "mv \"" . $file . "\" ";
$y = str_replace(" ", "_", $file); //Remove space.
$y = str_replace(",", "", $y); //Remove comma.
$y = str_replace("=", "", $y); //Remove equal.
$y = str_replace(";", "", $y); //Remove semi-colon.
$y = str_replace("'", "", $y); //Remove apostrophe.
$y = str_replace("(", "", $y); //Remove left parenthesis.
$y = str_replace(")", "", $y); //Remove right prenthesis.
$y = str_replace("$", "", $y); //Remove dollar sign.
$y = str_replace("[", "", $y); //Remove left bracket.
$y = str_replace("]", "", $y); //Remove right bracket.
$y = str_replace("&", "", $y); //Remove ampersand.
$y = str_replace("`", "", $y); //Remove accent aigou.
$y = str_replace("._", "_", $y); //Remove period underscore.
$y = str_replace("|", "_", $y); //Remove pipe.
$y = str_replace("/", "_", $y); //Remove forward slash.
$y = str_replace(":", "_", $y); //Remove colon.
$y = str_replace("!", "_", $y); //Remove exclaimation point.
//echo "mv " . $x . " " . $y . "<br />";
echo $x . " " . $y . "<br />";
// DO NOT USE
BECAUSE IT WILL PUT A CARRIAGE RETURN IN THE FILENAME!
}
//The built-in Linux rename utility is useful for removing the carriage return on files.
//Usage: rename $'
' '' *.txt*
//https://unix.stackexchange.com/questions/189784/remove-newlines-in-file-names
//php -f renamefiles.php > ~/public_html/rename.html
//Rename files that start with a dash or hyphen, use a double-dash:
// mv -- -filename.txt filename.txt
}
/*
NOTE: I got rid of the carriage return by zipping the files up and unzipping them.
*/
?>