I am working on a rename function to get rid of non alphanumeric chars in a file name.
After some searching in the forums I found a good solution to get rid of those chars but it doesn't seem to work for me.
echo $filename."\n";
$newfilenamecorrect=preg_replace("/^[a-z0-9A-Z.-_]+$/", '',$filename);
$newfilenamecorrect=dirname($path). '/' . $newfilenamecorrect;
echo $newfilenamecorrect."\n";
Where $filename
is the filename itself (example Picture.jpg),
$path
- is the original path + filename (example ./galleries/Picture.jpg)
$newfilenamecorrect
Should be the new filename including path and filename.
No idea why but when I run that I get echoes like:
000���5.jpg ./galleries/iPhone/000���5.jpg
2D-Art-Iataândesson-Cruz-Gnomon.jpg ./galleries/iPhone/2D-Art-Iataândesson-Cruz-Gnomon.jpg
I'm kinda new to php, so sorry for any stupid mistakes I've made :)