0

3 and 4 also must be valid, how can I do it using FILTER_VALIDATE_URL? FILTER_VALIDATE_URL not understanding international domains.

1. $url = 'https://example.com'; - Valid
2. $url = 'https://example.com/en/'; - Valid
3. $url = 'https://example.հայ'; - Invalid
4. $url = 'https://example.рус'; - Invalid
5. $url = 'https://exa_mple.com'; - Invalid


if (filter_var($url, FILTER_VALIDATE_URL)) {
   echo("Valid URL!");
} else {
   echo("Invalid URL!");
}
karen
  • 45
  • 1
  • 4
  • Check this - https://stackoverflow.com/questions/161738/what-is-the-best-regular-expression-to-check-if-a-string-is-a-valid-url – Tuhin Dec 06 '20 at 18:28

1 Answers1

0

You can use the IDN function to first convert the IDN to ASCII:

https://www.php.net/manual/en/function.idn-to-ascii.php

Evert
  • 75,014
  • 17
  • 95
  • 156