Punycode Converter is a PHP library that provides functions to encode and decode URLs using Punycode.
You can install the library via Composer. Run the following command:
composer require qdenka/punycode
use Qdenka\Punycode\Converter;
// Encode a URL to Punycode
$encodedUrl = Converter::encode('http://www.üñïçø∂é.com/привет#мир');
// Decode a Punycode URL back to its original form
$decodedUrl = Converter::decode('http://xn--tda.com/');
// Encode an array of URLs to Punycode
$urls = ['http://www.üñïçø.com/testcase', 'ßlåh.com'];
$encodedUrls = Converter::encodeFromArray($urls);
// Decode an array of Punycode URLs back to their original forms
$punycodeUrls = ['xn--tda.com', 'http://www.example.com/url1'];
$decodedUrls = Converter::decodeFromArray($punycodeUrls);
use Qdenka\Punycode\Identifier;
// Check if a URL is encoded IDN
$isPunycode = Identifier::isPunycode('http://xn--tda.com/');
// Check if a URL is Ascii
$isNotPunycode = Identifier::isUnicode('http://www.üñïçø.com/');