What are the best practices for creating a print preview feature in PHP?

When creating a print preview feature in PHP, it is important to generate a separate page that displays the content in a printer-friendly format. This can be achieved by creating a new PHP file specifically for the print preview and using CSS to style the content for printing. Additionally, you can provide a button or link on the original page that opens the print preview in a new window or tab.

<?php
// Original page content
echo "<h1>Print Preview Example</h1>";
echo "<p>This is the content that will be displayed in the print preview.</p>";

// Link to open print preview in a new window
echo "<a href='print-preview.php' target='_blank'>Print Preview</a>";
?>
```

In the `print-preview.php` file, you can style the content for printing using CSS:

```php
<?php
// CSS for print preview
echo "<style>
    body {
        font-family: Arial, sans-serif;
        font-size: 12pt;
    }
    h1 {
        color: #333;
        text-align: center;
    }
    p {
        color: #666;
        line-height: 1.5;
    }
</style>";

// Content for print preview
echo "<h1>Print Preview</h1>";
echo "<p>This is the content in a printer-friendly format.</p>";
?>