+ Reply to Thread
Results 1 to 5 of 5

Thread: php include

  1. #1
    Conmiro is offline x10 Sophmore Conmiro is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    140

    php include

    My friend did it once and it allowed you to use php include to create a webpage auto where it would automatically put the navigation to the left, and ur stats to the top and w/e everywhere else.

    The navigation file included links u could add to left nav which would update every other page so you wouldn't have to add the links to every page manually. It also had like the layout all made.

    The file would look like this as far as I recall:

    <php? include ('header.php') ?>
    Whatever text u put here would end up in a certain cell of the table.
    <php? include ('footer.php') ?>

    I don't know what the header.php and footer.php files need to have though.

  2. #2
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: php include

    header/footer.php either have more php code (<?php echo "This is a navbar!"?>), or standard html code.

    If using HTML code, you do NOT need to put in something like <html><body><img src='images/header.png' /></body></html> - the original document that's doing the including should already have the <html> and <body> tags in there, so you can just put "<img src='images/header.png' />" in header.php, and it'll include it as-is (I made this mistake lotsa times before I realized it was just including the text as-entered - really made the w3c validator angry XD )


    Side note: PHP tags open with <?php, not <php?. Just giving a heads up, it won't work if it's opened the wrong way
    Last edited by Livewire; 03-27-2009 at 11:37 PM.


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  3. #3
    geirgrusom is offline x10Hosting Member geirgrusom is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    9

    Re: php include

    As Livewire says, php include is like the #include preprocessor directive in C/C++
    It simply cuts and copies code into the new document with one exception:
    Even though include is inside <?php ?> tags, you still need to put this inside the included file, because include kinda temporarily cancels this.

    so
    Code:
    <?php include("header.php" ?>
    
    // ... header.php
    
    <a href="http://www.someurl.com">URL</a>
    Is correct. You do must not start an included page with ?> in order to add normal HTML.

  4. #4
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: php include

    also for correct syntax you would need a semi-colon at the end of the include

    <php? include ('header.php'); ?>

  5. #5
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: php include

    also, anything included will be executed as well.

    if your file is include_me.php is this
    Code:
    <?php echo 'Hello World!'; ?>
    Where the file is included, it will echo 'Hello World!'

    You can avoid this behavior by making a function
    Code:
    <?php function say_hello()
    {
        echo 'Hello World!';
    } ?>
    then including the file and calling the function say_hello()
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

+ Reply to Thread

Similar Threads

  1. PHP Include, file help!
    By stillDOLL in forum Programming Help
    Replies: 8
    Last Post: 10-07-2008, 04:26 AM
  2. PHP and new accounts
    By idani in forum Free Hosting
    Replies: 1
    Last Post: 09-21-2008, 01:49 PM
  3. include php within javascript
    By thezone1 in forum Programming Help
    Replies: 5
    Last Post: 04-24-2008, 12:50 PM
  4. php include is this possible
    By nahsorhseda in forum Programming Help
    Replies: 5
    Last Post: 12-28-2007, 12:09 PM
  5. Cambios IMPORTANTES en PHP.
    By Fedlerner in forum Noticias y Anuncios
    Replies: 1
    Last Post: 11-06-2007, 11:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers