Thread: including files in php

  1. #1
    Former Member
    Join Date
    Oct 2001
    Posts
    955

    including files in php

    Once again I need your help.

    I am still learning php 4, and from what I've learnt already, it's extremely cool a language. But I still have a doubt, and it is imperative that I know how to do this, or something similar in php 4

    When I do ASP, I can have the server totally paste a file inside another file when something's requested doing something like this

    <!-- #include file="validate.asp" -->

    which happens to be pretty cool since I can write functions that are used in many (if not all) files in another file, include it and call the function(s) when I need them

    I am currently moving my site from Intel/Windows NT/IIS/ASP/ODBC to SPARC/Solaris 9/Apache/PHP/MySQL, but I have a good structure in ASP, and I need to code the other page based on the first one.

    I need to be able to write functions that I can access from any file, so the first way I thought of doing so was with inline file including; but I read that you can make functions to be included in your PHP server... that would be good too.

    Does anyone knows how to do either of these solutions?

    Oskilian

  2. #2
    I'm not sure I understand what you mean, but to include a php-file inside a php-file, use
    PHP Code:
    include("thephpfile.php"); 
    You can only make custom functions in your own files, you can't "include them" in your server-program or whatever you meant. Check out the documentation/reference at www.php.net if you don't already have it.
    Last edited by Xmevs; 07-02-2002 at 08:08 AM.

  3. #3
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    Thanks, I noticed that

    <?php include_once 'myfile.php' ?>

    also works

    Oskilian

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    Originally posted by oskilian
    Thanks, I noticed that

    <?php include_once 'myfile.php' ?>

    also works

    Oskilian
    include_once() is different from include()
    I suggest you taking a look :
    Include()

    Include_once()

  5. #5
    To compare it with C/C++ you can say:

    include:
    #include "file"

    include once:
    #ifndef include
    #define include
    #include "file"
    #endif
    (assuming that you use the define thingy everywhere this file is included...)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Makefile producing a list of files.
    By leonm54 in forum Tech Board
    Replies: 1
    Last Post: 07-23-2007, 09:54 AM
  3. including files
    By Deb in forum C Programming
    Replies: 1
    Last Post: 04-20-2007, 11:06 AM
  4. Curiosity: including .cpp files
    By Mr_Miguel in forum C++ Programming
    Replies: 20
    Last Post: 01-17-2007, 11:33 PM
  5. including other .c files
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 02-24-2002, 09:56 PM