3v4l.org

run code in 300+ PHP versions simultaneously
<?php $urls = [ 'https://example.com/api/', 'https://www.example.com/test-subpath', 'https://www.example.com', 'example.com/test/page', 'www.example.com', 'www.subdomain.example.com', 'https://www.subdomain.example.com', 'subdomain.example.com', 'http://subdomain.example.com', 'https://subdomain.example.com', ]; function checkUrl(string $url): bool { return (bool)filter_var($url, FILTER_VALIDATE_URL); } foreach ($urls as $url) { if (checkUrl($url)) { echo $url . ' is a valid URL' . PHP_EOL; continue; } $urlWithProtocol = 'https://' . $url; if (checkUrl($urlWithProtocol)) { echo $urlWithProtocol . ' with added protocol is a valid URL' . PHP_EOL; continue; } echo $url . ' is not a valid URL' . PHP_EOL; }
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
https://example.com/api/ is a valid URL https://www.example.com/test-subpath is a valid URL https://www.example.com is a valid URL https://example.com/test/page with added protocol is a valid URL https://www.example.com with added protocol is a valid URL https://www.subdomain.example.com with added protocol is a valid URL https://www.subdomain.example.com is a valid URL https://subdomain.example.com with added protocol is a valid URL http://subdomain.example.com is a valid URL https://subdomain.example.com is a valid URL

preferences:
64.18 ms | 408 KiB | 5 Q