<?php // Create new stdClass Object $init = new stdClass; // Add some test data $init->foo = "2019-02-15T11:12:28"; $init->bar = new stdClass; $init->bar->baaz = "Testing <the"; $init->bar->fooz = new stdClass; $init->bar->fooz->baz = "Testing<> again"; $init->foox = "Just<> test"; function clean($string) { return preg_replace("/[^a-zA-Z0-9_\s]/", "", $string); } function striploop($obj){ $stipfields=['FirstName','LastName','MailingStreet','MailingCity']; foreach($obj as $key => $item) { if(is_object($item) || is_array($item)) striploop($item); if(is_string($item) && in_array($key,$stipfields)) $obj->$key=clean($item); } return $obj; } // Print objects and array print_r(striploop($init));
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more