PHP code example of centralnic-reseller / idn-converter
1. Go to this page and download the library: Download centralnic-reseller/idn-converter 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/ */
centralnic-reseller / idn-converter example snippets
use CNIC\IDNA\Factory\ConverterFactory;
// Convert a domain string to Unicode format
$domain = "example.com";
$unicodeDomain = ConverterFactory::toUnicode($domain);
echo "Unicode Domain: $unicodeDomain\n";
use CNIC\IDNA\Factory\ConverterFactory;
// Convert a domain string to Punycode format
$unicodeDomain = "example.com";
$punycodeDomain = ConverterFactory::toASCII($unicodeDomain);
echo "Punycode Domain: $punycodeDomain\n";
use CNIC\IDNA\Factory\ConverterFactory;
// Convert multiple domain strings to Unicode and Punycode formats
$domains = ["example.com", "münchen.de", "рф.ru"];
$convertedDomains = ConverterFactory::convert($domains);
foreach ($convertedDomains as $domain) {
echo "Unicode Domain: {$domain['IDN']}, Punycode Domain: {$domain['PUNYCODE']}\n";
}
### `ConverterFactory::toUnicode($keyword, $options = [])`
Converts a domain string to Unicode format.
- **Parameters:**
- `$keyword` (string): The domain string to convert.
- `$options` (array): Additional options for the conversion process (optional).
- **Returns:** The converted domain in Unicode format, or `false` if the keyword is empty.
### `ConverterFactory::toASCII($keyword, $options = [])`
Converts a domain string to Punycode format.
- **Parameters:**
- `$keyword` (string): The domain string to convert.
- `$options` (array): Additional options for the conversion process (optional).
- **Returns:** The converted domain in Punycode format, or `false` if the keyword is empty.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.