How can server uptime be retrieved and displayed in a specific format using PHP?
To retrieve server uptime and display it in a specific format using PHP, you can use the `exec()` function to execute a command that retrieves the uptime information from the server. You can then format this information as needed using PHP functions like `date()`.
<?php
// Execute the 'uptime' command and store the output in a variable
$uptime = exec('uptime');
// Extract the uptime information from the output
$uptime = explode(' up ', $uptime)[1];
$uptime = explode(',', $uptime)[0];
// Display the formatted uptime
echo "Server uptime: " . trim($uptime);
?>