[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/algo26-matthias/idna-convert/src/ -> ToUnicode.php (source)

   1  <?php
   2  namespace Algo26\IdnaConvert;
   3  
   4  use Algo26\IdnaConvert\Punycode\FromPunycode;
   5  use Algo26\IdnaConvert\TranscodeUnicode\TranscodeUnicode;
   6  
   7  class ToUnicode extends AbstractIdnaConvert implements IdnaConvertInterface
   8  {
   9      /** @var TranscodeUnicode */
  10      private $unicodeTransCoder;
  11  
  12      /** @var FromPunycode */
  13      private $punycodeEncoder;
  14  
  15      public function __construct()
  16      {
  17          $this->unicodeTransCoder = new TranscodeUnicode();
  18          $this->punycodeEncoder = new FromPunycode();
  19      }
  20  
  21      public function convert(string $host): string
  22      {
  23          // Drop any whitespace around
  24          $input = trim($host);
  25  
  26          $hostLabels = explode('.', $input);
  27          foreach ($hostLabels as $index => $label) {
  28              $return = $this->punycodeEncoder->convert($label);
  29              if (!$return) {
  30                  $return = $label;
  31              }
  32              $hostLabels[$index] = $return;
  33          }
  34  
  35          return implode('.', $hostLabels);
  36      }
  37  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer