SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Assigning a variable to a file.

    Hello everyone,

    I am trying to achieve something very simple.

    I have a footer.php file which I would like to include() into my index.php

    Code:
    /*footer.php*/
    
        <ul>
            <li><a href="#">About Us</a></li>
            <li><a href="#">Financing</a></li>
            <li><a href="#">Contact Us</a></li>
        </ul>
    Currently, I am including the footer into my index.php using the following method:

    Code:
    <?php
    if(file_exists("includes/footer.php")){
    include ("includes/footer.php");
    }
    ?>
    As you can see, I am repeating "includes/php" twice. I figured that it is easier to assign this file as a variable, so I may use the following code instead:

    Code:
    <?php
    if(file_exists($footer)){
    include ($footer);
    }
    ?>
    But I have no idea how to assign a file as a variable. Thanks for any tips.

  2. #2
    Twitter: @TimIgoe silver trophy TimIgoe's Avatar
    Join Date
    Feb 2005
    Location
    Blackpool, UK
    Posts
    1,058
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    In this case, $footer = 'includes/footer.php'; is all you need

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, Tim.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •