How can PHP be used to check the validity of HTTP links, including syntax and status codes?

To check the validity of HTTP links in PHP, you can use the `get_headers()` function to retrieve the headers of the URL and check the HTTP status code. You can also use regular expressions to validate the syntax of the URL.

function checkLinkValidity($url) {
    $headers = get_headers($url);
    
    if (strpos($headers[0], '200') !== false) {
        echo "Link is valid and returns a 200 OK status code.";
    } else {
        echo "Link is invalid or returns a non-200 status code.";
    }
}

$url = "https://www.example.com";
checkLinkValidity($url);