You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
434B

  1. <?php
  2. /**
  3. * Validates an URL.
  4. *
  5. * @param string|null $url
  6. * @param string|null $hostname
  7. *
  8. * @return bool
  9. */
  10. function isValidUrl( ? string $url, ? string $hostname) : bool
  11. {
  12. if ($url === null) {
  13. return false;
  14. }
  15. if (trim($url) === '') {
  16. return false;
  17. }
  18. if (filter_var($url, FILTER_VALIDATE_URL) === false) {
  19. return false;
  20. }
  21. return parse_url($url)['host'] !== $hostname;
  22. }