adiafora/laravel-punycode

Package for decoding domains in punycode for Laravel 5

1.3 2019-07-23 19:15 UTC

This package is auto-updated.

Last update: 2024-11-12 05:08:39 UTC


README

This package converts a Unicode encoded domain name to a IDNA ASCII form and vice-versa.

This package is based on another package - fomvasss/laravel-punycode. But the idna_convert class is taken as the main class. And it allows you to use a domain in any writing: only domain, domain with www, Protocol, script, parameters, and so on.

If You accidentally encoded an English domain in punycode, then nothing will happen to it, no errors and unexpected results. You can safely use this package on all domains, it will do everything for You.

Install

Run:

    composer require "adiafora/laravel-punycode"

For Laravel < 5.5 Add in ServiceProvider to the providers array in config/app.php

    Adiafora\Punycode\PunycodeServiceProvider::class,

Usage

Usage facade

You can now using the Facade by default.

For Laravel < 5.5 Add in Facade to the aliases array in config/app.php

    'Punycode' => Adiafora\Punycode\Facades\Punycode::class,

Example usage:

    var_dump(Punycode::encode('мой-веб-сайт.сайт'));
    // outputs: xn-----8kcceszgtu3bo.xn--80aswg

    var_dump(Punycode::decode('xn-----8kcceszgtu3bo.xn--80aswg'));
    // outputs: мой-веб-сайт.сайт

Usage helper functions

    punycode_encode('мой-веб-сайт.сайт');
    punycode_decode('xn-----8kcceszgtu3bo.xn--80aswg');

License

The MIT License (MIT). Please see License File for more information.