I have a variable that will become the name of a file on hard drive/server so I need to eliminate EVERYTHING from the variable except for alphabetical & numerical values and characters allowed in file names (such as dash -, underscore _ etc)...
I have looked in the manual and I found this:
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out html tags
"'([\r\n])[\s]+'", // Strip out white space
"' '", // Strip out white space
"'&(quot|#34);'i", // Replace html entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // evaluate as php
$replace = array ("",
"",
"\\1",
"",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$name_file = preg_replace ($search, $replace, $name_artist);
I think I could use this function if I manually added ALL the symbols that are not allowed to the $search array but I was thinking that there must be an easier way, a specific function that eliminates everything except alphanumeric files. Isn't there?
I looked on the manual but did not find anything... I found rawurlencode() that does exactly what I need (replaces all non-alphanumerical values except for _ and - and .) but in rawurlencode() it replaces it with hex ditigs... I need to replace it with, say, underscores...
Also, since I am asking about this function, can somebody tell me what the "i", the "si" and the "+" stand for in the above function... Out of curiosity... I have looked on the manual but couldn't find that information...
Thanks and sorry for asking so many questions...