First a simple example and then one explaining how to catch errors.
<?php
// ISO-8859-1 encoded string
echo idn_to_ascii(utf8_encode('t?st.de')));
// Cannot convert a domain name to ASCII that contains non-ASCII chars but already starts with "xn--"
$ascii = idn_to_ascii("xn--".chr(0xC3).chr(0xA4), $errorcode);
if ($ascii === false) {
printf("Detected error %d: %s\n", $errorcode, idn_strerror($errorcode));
}
?>
Результатом выполнения данного примера
будет что-то подобное:
xn--tst-qla.de
Detected error 8: Input already contain ACE prefix (`xn--')