I want to remove all the illegal character and replace the space with underscore so i use this code:
function sanitize_file_name($filename) {
$filename = preg_replace("/([^A-Za-z0-9_\-\.]|[\.]{2})/", "", $filename);
return basename($filename);
}
for example i have a filename like "www..//../no way" when i sanitize it, it become 'wwwno_way'.
it work to remove the other character that i want but the problem is i don't know how to replace the space with underscore at the same time using preg_replace. Is it posible? and how i can accomplish it?