3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class StringNormalizer { public function transliterate($inputString) { return String::transliterate(trim($inputString)); } public function toLowerTransliterate($inputString) { return strtolower($this->transliterate($inputString)); } public function transliterateArray(array $inputs) { $result = array(); foreach ($inputs as $input) { $transiteratedInput = $this->transliterate($input); $result[strtolower($transiteratedInput)] = $transiteratedInput; } return $result; } public function transliterateKeyArray(array $inputs) { $result = array(); foreach ($inputs as $key => $input) { $result[$this->toLowerTransliterate($key)] = $input; } return $result; } } class String { const IN_CHARSET = 'UTF-8'; const OUT_CHARSET = 'ASCII//TRANSLIT'; const ALLOWED_CHARACTERS_FILTER = '/[^0-9a-zA-Z_\. \(\)\-]+/'; const DEFAULT_PREFIX = 'export_'; public static function transliterate($inputString) { return $outputString = preg_replace(self::ALLOWED_CHARACTERS_FILTER, '', iconv(self::IN_CHARSET, self::OUT_CHARSET, $inputString)); } private function __construct() { } } $strings = array( ' aąbcćdeęfghijklłmnńoóprsśtuwyzźżAĄBCĆDEĘFGHIJKLŁMNŃOÓPRSŚTUWYZŹŻ ', ' aäbcdefghijklmnoöpqrsẞtuüvwxyzAÄBCDEFGHIJKLMNOÖPQRSßTUÜVWXYZ ', ' _. ()-\\/ ' ); $sut = new StringNormalizer(); $results = array(); foreach ($strings as $string) { $results[] = $sut->transliterate($string); } var_dump($results) ;
Output for 7.0.0 - 7.0.2
Fatal error: Cannot use 'String' as class name as it is reserved in /in/FDO5v on line 37
Process exited with code 255.
Output for 5.3.21 - 5.6.28
array(3) { [0]=> string(46) "abcdefghijklmnoprstuwyzABCDEFGHIJKLMNOPRSTUWYZ" [1]=> string(54) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSssTUVWXYZ" [2]=> string(6) "_. ()-" }