$url = "http://www.example.com"; if (filter_var($url, FILTER_VALIDATE_URL) && isAbsoluteUrl($url)) { // do something with absolute URL } else { // handle invalid or non-absolute URL }
$url = "/path/to/some/page.html"; if (filter_var($url, FILTER_VALIDATE_URL) && isAbsoluteUrl($url)) { // do something with absolute URL } else { // handle invalid or non-absolute URL }The isAbsoluteUrl function is not part of the PHP core library, but it may be included in various third-party libraries or frameworks. It is also possible to define the function in your own code if needed.