Strip HTML Tags From Array

Description: Strips all HTML tags from an array using a recursive method. Great for forms where all HTML tags are not allowed.
Tested Platform: PHP 7+
Language: PHP
// StripAllFields: Strips all HTML Tags from array recursively (Great for forms)
// Expects: Array of fields to strip.
// Returns: Nothing, original array is stripped.

function stripAllFields(&$fields) {
     foreach ($fields as $key => $value) {
          if (is_array($fields[$key])) { stripAllFields($fields[$key]); }
          else { $fields[$key] = strip_tags($value); }

Posted: March 18, 2023

Return to the snippets listing