PHP code example of qdenka / punycode

1. Go to this page and download the library: Download qdenka/punycode library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

qdenka / punycode example snippets


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/');