PHP

Filter and Sanitize

September 2018

filter_input // Sanitize input if (is_numeric($_POST[$post_key])) { $filtered_db_inputs[$post_key] = filter_input(INPUT_POST, $post_key, FILTER_SANITIZE_NUMBER_INT); } else { $filtered_db_inputs[$post_key] = filter_input(INPUT_POST, $post_key, FILTER_SANITIZE_STRING); } Trimming Use trim, ltrim, and rtrim to remove substrings from the beginning and end of a string. $string = ‘ _hello_ ‘; $trimmed = trim( $string ); // Returns “_hello_” echo trim( $trimmed, ‘_’