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::convertBulk($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.
### `ConverterFactory::convert($keywords, $options = [])`
Converts a single domain string (or a list of domain strings) to both Unicode and Punycode formats.
- **Parameters:**
- `$keywords` (string|array): The domain string, or a list of domain strings, to convert.
- `$options` (array): Additional options for the conversion process (optional).
- **Returns:** An array with `idn` and `punycode` entries; for a list input, one such array per input keyword, keyed like the input.
### `ConverterFactory::convertBulk($keywords, $options = [])`
Converts a list of domain strings to both Unicode and Punycode formats, preserving the input keys.
- **Parameters:**
- `$keywords` (array): The domain strings to convert.
- `$options` (array): Additional options for the conversion process (optional).
- **Returns:** One array with `idn` and `punycode` entries per input keyword, keyed like the input.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.