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 5
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); }
     }
}

Submitted: December 24, 2012

Return to the snippets listing