3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DomainName { private $name; private $escapedName; public function __construct($name) { $decodeUnicodeName = static::decodeUnicode($name); $this->name = $decodeUnicodeName; $this->escapedName = static::escapeDomainName($decodeUnicodeName); } public function containsSubdomain() { return substr_count($this->name, '.') >= 2; } public static function escapeDomainName($name) { return preg_replace('/\./', '-', $name); } public static function decodeUnicode(string $name): string { return preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match) { return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE'); }, $name); } public function __toString(): string { return (string)$this->name; } } $name = 'apotheke-altenessen-s\u00fcd.de'; $test = new DomainName($name); print_r($test->name);

preferences:
39.09 ms | 402 KiB | 5 Q