I'm making a SWF uploader and have my HTML form done.
It works totally fine until I upload a SWF file with spaces in the name.
How can I replace whitespace with underscores?
I have tried...
str_replace(" ","_", $file);
...and...
preg_replace(" ","_", $file);
The
\s
character class will match whitespace characters. I've added the+
quantifier to collapse multiple whitespace to one_
. If you don't want that, remove the+
.I usually approach it from the other side and only allow characters from a white-list; I replace everything except these characters:
the function is correct but you have to assign it to a variable.