simplify sanitize() function

This commit is contained in:
Piotr KUCHARSKI 2014-11-24 20:59:30 +01:00
parent 14cdaf7dd1
commit f79debe096

View file

@ -60,29 +60,9 @@ function flipHorizontal(&$img) {
}
}
function str_split_php4( $text, $split = 1 ) {
// place each character of the string into and array
$array = array();
for ( $i=0; $i < strlen( $text ); )
{
$key = NULL;
for ( $j = 0; $j < $split; $j++, $i++ )
{
$key .= $text[$i];
}
array_push( $array, $key );
}
return $array;
}
function sanitize($name)
{
// Sanitize image filename (taken from http://iamcam.wordpress.com/2007/03/20/clean-file-names-using-php-preg_replace/ )
$fname=$name;
$replace="_";
$pattern="/([[:alnum:]_\.-]*)/";
$fname=str_replace(str_split_php4(preg_replace($pattern,$replace,$fname)),$replace,$fname);
return $fname;
function sanitize($name) {
// note: this allows for collisions
return preg_replace("/[^[:alnum:]_.-]/", "_", $name);
}
// Make sure the "thumbs" directory exists.