Are there any best practices for handling expandable links in PHP to ensure compatibility with users who have JavaScript disabled?

When handling expandable links in PHP to ensure compatibility with users who have JavaScript disabled, the best practice is to use PHP to toggle the visibility of the content instead of relying on JavaScript. This can be achieved by using PHP to generate the necessary HTML structure and CSS classes to show or hide the content based on user interaction.

<?php
$expanded = isset($_GET['expanded']) ? $_GET['expanded'] : false;

echo '<a href="?expanded=1">Toggle Content</a>';

if ($expanded) {
    echo '<div class="expanded-content">This is the expandable content</div>';
} else {
    echo '<div class="collapsed-content">Click the link to expand the content</div>';
}
?>