php - Replace all non-printable UTF-8 characters with spaces -


i need sanitaze user input , need remove characters can cause problems such null byte or useless ones(such \n or \t), because inputs or strings or html code. @ moment i'm using remove tab, break-line, etc:

preg_replace('/\s+/','',$_post['id']) 

but isn't sufficent, have found this:

preg_replace( '/[^[:print:]]/',' ',$_post['val']) 

but don't understand if strips characters shouldn't deleted, such german or arabic chars or punctation or symbols

according php regex character classes [:print:] includes "printing characters, including space".

that means "visible characters , spaces (i.e. except control characters, etc.)" (see http://www.regular-expressions.info/posixbrackets.html)

  • ascii characters: [\x20-\x7e]
  • unicode: \p{c}

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -