Remove invalid characters from a filename

<?php
function filename_safe($filename) {
$temp $filename;

// Lower case
$temp strtolower($temp);

// Replace spaces with a ’_’
$temp str_replace(“ ”“_”$temp);

// Loop through string
$result ;
for (
$i=0$i<strlen($temp); $i++) {
if (
preg_match(‘([0-9]|[a-z]|_)’$temp[$i])) {
$result $result $temp[$i];
}
}

// Return filename
return $result;
}
?>



Search the Web with Google

1 Response to “Remove invalid characters from a filename”


  1. 1 aaaaa

    thanks

    1

Leave a Reply