From fb008e1b594c310f15be98e20ea6d9c452e5cea4 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 9 Jul 2024 16:43:21 +0200 Subject: [PATCH] Add function for ensuring all input in an array is strings --- src/MD_STD_IN.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/MD_STD_IN.php b/src/MD_STD_IN.php index 355eaa8..8dc23ef 100644 --- a/src/MD_STD_IN.php +++ b/src/MD_STD_IN.php @@ -131,6 +131,27 @@ final class MD_STD_IN { } + /** + * Validates an input array for all entries being strings. Unsets empty values. + * This is especially useful for parsed JSON. + * + * @param array $inputs Input array. + * + * @return array + */ + public static function sanitize_text_array(array $inputs):array { + + $output = []; + + foreach ($inputs as $key => $input) { + if (empty($input)) continue; + $output[$key] = self::sanitize_text($input); + } + + return $output; + + } + /** * Retrieves HTTP input texts from GET or POST variables, whatever is provided. * If neither is given, returns a provided default.