Search code examples
phpclassincludefooter

How can I put all includes on one page with classes?


For a school project I need to put all returning code into an include. I want it all on one page, but I can't get it to work. Creating an include is no problem, but I want them all in one PHP page. I have the following code, but it is wrong:

//footer
<?php

class footer
{
echo '<a href="login.php">Account</a>';
echo '<a href="subscription.php">Subscription</a>';
echo '<a href="about.php">About us</a>';
echo '<a href="termsofuse.php">Terms of Use</a>';
echo '<small>&copy; 2017, (myname)  &  (name partner)</small>';
}
?>

How do I have to modify the code, so that it is correct?


Solution

  • Assign the html code to variables.

    <?php $footer = "<a href="login.php">Account</a>
                     <a href="subscription.php">Subscription</a>
                     <a href="about.php">About us</a> 
                     <a href="termsofuse.php">Terms of Use</a>
                     <small>&copy; 2017, (myname)  &  (name partner)</small>"
    ?>
    

    After that you only need to include the one PHP file and <?php echo $footer ?> for all parts of your page