How can PHP be used to determine the availability of a website and display it as online or offline?

To determine the availability of a website using PHP, you can use the `get_headers()` function to check the response headers of the website. If the response code is 200, it means the website is online, otherwise it is offline.

$url = 'https://www.example.com';
$headers = @get_headers($url);

if ($headers && strpos($headers[0], '200')) {
    echo 'Website is online';
} else {
    echo 'Website is offline';
}