What does whitelisting involve for inputs to prevent html and xss injection?
From what I gather preg_replace with regular expression is a good start. What else?
It is easier to sanitize output than input. Apply the correct escaping every time your data passes from one context to the next. For example, apply mysqli_real_escape_string when data is passed to the database (if you are using the MySQLi extension), apply htmlspecialchars when you output the data as HTML and so on.