I can not reproduce your problem, for me the line that is output is:
$replaceUnder = 'ABC_test 001-2.jpg'; $makeSpace = preg_replace("/[^a-zA-Z0-9\s]/", " ", $replaceUnder); print_r($makeSpace);
.
dubugging your code
I looked at the code you pasted and found some errors that might be related, maybe not:
I get an error on this line because replaceUnder is not defined:
$makeDash = str_replace(" ", "-", $replaceUnder);
since you commented on this line:
//$replaceUnder = str_replace("_", "-", $class);
I think you also wanted to comment on this. It is not clear what you are trying to do and why you have all of these replacements. If you are just trying to revoke file names with all characters replaced, here is how I did it and all letters were replaced with spaces:
<?php //set images directory $directory = './'; try { foreach ( new DirectoryIterator($directory) as $item ) { if ($item->isFile()) { $path = $directory . "" . $item; // remove ending/filetype - the other method doesn't support 4 letter file endings $name = basename($item); $fixedName = preg_replace("/[^a-zA-Z0-9\s]/", " ", $name); echo "Name: $fixedName\n"; } } } //if directory is empty throw an exception. catch(Exception $exc) { echo 'the directory you chose seems to be empty'; } ?>
I think that all your problems stem from the name of the variables. Consider including error warnings - they will let you know if you are referring to variables that are not defined.
source share