/** * Recursively cleans arrays, objects, and strings. Removes ASCII control * codes and converts to the requested charset while silently discarding * incompatible characters. * * @param mixed $str * @return string */ public static function clean($str) { if (is_array($str) || is_object($str)) { foreach ($str as $key => $val) { $str[$key] = self::clean($val); } } else { if (is_string($str) && $str !== '') { $str = mb_strtolower(UTF8::strip_ascii_ctrl($str)); if (!UTF8::is_ascii($str)) { $str = strtolower(self::transliterate_to_ascii($str)); } if (!UTF8::is_ascii($str)) { $str = UTF8::strip_non_ascii($str); } } } return $str; }
/** * Tests UTF8::strip_non_ascii * * @test * @dataProvider provider_strip_non_ascii */ public function test_strip_non_ascii($input, $expected) { $this->assertSame($expected, UTF8::strip_non_ascii($input)); }