diff --git a/composer.json b/composer.json index 4347da9..0fa85a9 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,10 @@ "require-dev": { "algo26-matthias/idna-convert": "^3.0" }, + "suggest": { + "ext-mbstring": "Install ext/mbstring for using input / output other than UTF-8 or ISO-8859-1", + "ext-iconv": "Install ext/iconv for using input / output other than UTF-8 or ISO-8859-1" + }, "autoload-dev": { "psr-4": { "StevieRay\\": "src" diff --git a/src/Generator.php b/src/Generator.php index 860e841..540d017 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -3,6 +3,7 @@ namespace StevieRay; use Algo26\IdnaConvert\ToIdn; +use Algo26\IdnaConvert\EncodingHelper\ToUtf8; class Generator { @@ -44,15 +45,21 @@ public function domainWorker() throw new \RuntimeException('Error opening file ' . $domainsFile); } $lines = array(); + $IDN = new ToIdn(); + $encodingHelper = new ToUtf8(); + while (($line = fgets($handle)) !== false) { $line = trim(preg_replace('/\s\s+/', ' ', $line)); // convert internationalized domain names - if (preg_match('/[А-Яа-яЁёɢ]/u', $line)) { + if (preg_match('/[А-Яа-яЁёöɢ]/u', $line)) { + $IDN = new ToIdn(); - $line = $IDN->encode($line); + $line = $encodingHelper->convert($line); + + $line = $IDN->convert($line); }