How can PHP be used to create a printer-friendly version of a webpage?

To create a printer-friendly version of a webpage using PHP, you can create a separate stylesheet specifically for printing that hides unnecessary elements like navigation bars, advertisements, and other non-essential content. You can then use PHP to detect when the page is being printed and dynamically switch to the printer-friendly stylesheet for a cleaner and more readable printout.

<?php
// Check if the page is being printed
if(isset($_GET['print'])){
    echo '<link rel="stylesheet" type="text/css" href="print.css" media="print">';
}
?>