Skip to content

Commit

Permalink
🕵️‍♂️ update encode to convert
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevie-Ray committed Nov 5, 2019
1 parent bf44462 commit 88423d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 9 additions & 2 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace StevieRay;

use Algo26\IdnaConvert\ToIdn;
use Algo26\IdnaConvert\EncodingHelper\ToUtf8;

class Generator
{
Expand Down Expand Up @@ -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);

}

Expand Down

0 comments on commit 88423d4

Please sign in to comment.