Requests_IDNAEncoder::to_ascii()
Convert a UTF-8 string to an ASCII string using Punycode
{} It's a method of the class: Requests_IDNAEncoder{}
No Hooks.
Return
String
. ASCII string
Usage
$result = Requests_IDNAEncoder::to_ascii( $string );
- $string(string) (required)
- ASCII or UTF-8 string (max length 64 characters)
Code of Requests_IDNAEncoder::to_ascii() Requests IDNAEncoder::to ascii WP 6.0
public static function to_ascii($string) { // Step 1: Check if the string is already ASCII if (self::is_ascii($string)) { // Skip to step 7 if (strlen($string) < 64) { return $string; } throw new Requests_Exception('Provided string is too long', 'idna.provided_too_long', $string); } // Step 2: nameprep $string = self::nameprep($string); // Step 3: UseSTD3ASCIIRules is false, continue // Step 4: Check if it's ASCII now if (self::is_ascii($string)) { // Skip to step 7 if (strlen($string) < 64) { return $string; } throw new Requests_Exception('Prepared string is too long', 'idna.prepared_too_long', $string); } // Step 5: Check ACE prefix if (strpos($string, self::ACE_PREFIX) === 0) { throw new Requests_Exception('Provided string begins with ACE prefix', 'idna.provided_is_prefixed', $string); } // Step 6: Encode with Punycode $string = self::punycode_encode($string); // Step 7: Prepend ACE prefix $string = self::ACE_PREFIX . $string; // Step 8: Check size if (strlen($string) < 64) { return $string; } throw new Requests_Exception('Encoded string is too long', 'idna.encoded_too_long', $string); }