Functions
WebDev/*nix assorted functions & hacks
Search
find all
Array
-
Bash
-
Classes
-
Config
-
DateTime
-
Debug
-
dotjs
-
File
-
foooo
-
Git
-
HTML
-
Images
-
Javascript
-
Linux
-
Math
-
Misc
-
MySQL
-
OS X
-
Reading
-
Redis
-
Shell scripts
-
snippets
-
SQL
-
Strings
-
TextMate
-
Web
-
\(^o^)/ Fun!
-
_Misc hacks
-
_Pages
File
clean_filename($filename)
duplicate_name($name, etc)
fetch_dirlist($path='', $exts='')
file_ext($file)
file_label($file, $label)
fsize($x)
resize_image($image, $sizes)
7
found
auth
Name:
Category: File
Body:
// /Somehow/, this has been sitting here for bloody ages, with a pattern that *removed* the valid characters // instead of leaving them. Srslywtfbbq. I never noticed since I was copying function files up and down // with a working alternative.. //____________________________ // clean_filename($filename) / function clean_filename($filename) { # \w for any word character; some punctuation, range of high-ASCII (192-255), couple isolated cases, and the '-' $pattern = '/[^\w.!_À-ÿšŽŠžŸ-]+/'; return preg_replace ($pattern, '', str_replace(' ', '_', $filename)); } // this was the alternative //____________________________ // clean_filename($filename) / function clean_filename($filename) { $filename = str_replace(' ', '_', $filename); // \w for any word character; some punctuation, range of high-ASCII (192-255), couple isolated cases, and the '-' $pattern = '/[\w.!_À-ÿšŽŠžŸ-]+/'; preg_match_all ($pattern, $filename, $matches); $filename = implode('', $matches[0]); $filename = preg_replace('/_+/', '_', $filename); return $filename; }
Footer