eHow launches Android app: Get the best of eHow on the go.

How To

How to Include a File in PHP

Contributor
By Launie Sorrels
eHow Contributing Writer
(0 Ratings)
Include a File in PHP
Include a File in PHP
www.osoft.com

Including a file in PHP requires one simple statement: "include." For the purposes of this tutorial we are going to create two PHP files. The first file is the one that you want to add into your include statement. The second file will be the calling file that has the include statement within it. To test the PHP files you will have to install PHP onto your local machine or have a site to upload your PHP files to.

Difficulty: Moderately Easy
Instructions

    Create the First File, Test.php

  1. Step 1

    Open a simple text editor like Wordpad or Notepad. Microsoft Word and higher level word processors add a lot of unwanted formats that can interfere with the code.

  2. Step 2

    Type in the code that you want the second file to call. Here is an example:

    <html>
    <body>
    <a href=http://www.thisisatest.com/index.php>Home</a> -
    <a href=http://www.thisisatest.com/about.php>About</a> -
    <a href=http://www.thisisatest.com/php.php>PHP coding</a><br/>

  3. Step 3

    Save the file as a PHP file. We will call it "Test.php."

  4. Create the Second File, index.php

  5. Step 1

    Open a simple text editor like Wordpad or Notepad if you closed it in the first section of this article.

  6. Step 2

    Type in the following code to call "Test.php:"

    <?php include ("test.php");?>
    <p> Welcome to my homepage. Select an option from the above links.</p>
    </body>
    </html>

  7. Step 3

    Save the file as "index.php." When a website is opened it defaults to the index file. Now when someone accesses your website they will see the following:
    Home -- About -- PHP coding
    Welcome to my homepage. Select an option from the above links.

Tips & Warnings
  • PHP is a scripting language. You should have some programming experience in understanding and properly executing HTML code before using PHP.
Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Tags
Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

eHow Computers
eHow_eHow Technology and Electronics