Currently, these are the preparations I’m making:
- Convert to lowercase.
- Strip HTML tags.
- Check if tag already exists
Are there any other things that I consider?
note: Tags may be in Arabic.
here the method i use
function sanitize_tag($tag){
//strip slashes
if(get_magic_quotes_gpc()) {
$tag = stripslashes(trim($tag));
}
//Remove white spaces
$tag = preg_replace('/\s\s+/',' ',$tag);
$tag = trim($tag);
$tag = ltrim($tag);
$tag=filter_var($tag, FILTER_SANITIZE_STRING);
return $tag;
}
If you are going to implement a
FULLTEXTtag searching scheme (likemysqlicious), make sure that your tags do not include word separators.Say, a dash (
-) is a word separator inMySQL, while an underscore (_) is not.So a search like this:
will incorrectly return
sql-serverbut (correctly) will not returnsql_server.