Results 1 to 7 of 7

Thread: How to use include() in PHP?

  1. #1
    Join Date
    May 2009

    How to use include() in PHP?

    Hello friends,
    Let me tell you that I am not good in PHP programming language. I have recently started working with the PHP, so I don't have much idea about it. But I am not new to programming language, since I have done C++, C# and Core Java. I need some information about the include(). Basically I don't know much about the include() in PHP, but it should be similar to other programming language. So please help me by explaining how to use include() in PHP? Thanks in Advance !!!

  2. #2
    Join Date
    Mar 2008

    Re: How to use include() in PHP?

    The include() statement includes and evaluates the specified file. Files are included based on the file path given or, if none is given, the include_path specified. The include() construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error. PHP considers each entry in the include path separately when looking for files to include. An include_path string specifies a list of directories where the require(), include(), fopen(), file(), readfile() and file_get_contents() functions look for files. The format is like the system's PATH environment variable: a list of directories separated with a colon in Unix or semicolon in Windows.

  3. #3
    Join Date
    Oct 2005

    Re: How to use include() in PHP?

    The following is the Unix include_path :
    PHP Code:
    And the following is the Windows include_path :
    PHP Code:
    Using a "." in the include path allows for relative includes as it means the current directory. However, it is more efficient to explicitly use include './file' than having PHP always check the current directory for every include.

  4. #4
    Join Date
    Aug 2006

    Re: How to use include() in PHP?

    If a path is defined (full path or relative), the include_path will be ignored. For example, if a filename begins with .. /, PHP will search the parent folder to find the file specified. When a file is included, the code it contains inherits the variable scope of the line where the include occurs. All variables available at that line in the calling file will be available in the called file, from this point. However, all functions and classes defined in the included file have global scope. The scope of a variable depends on the context in which the variable is defined. For most variables, the scope for an entire PHP script. But when you define a function, the scope of a variable defined in this function is local to the function.
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  5. #5
    Join Date
    Feb 2008

    Re: How to use include() in PHP?

    If the include occurs inside a function, the code included will be considered part of the function. It amends the context of available variables. An exception to this rule are magic constants are analyzed by the parser before the include occurs. It is important to note that when a file is include () or require (), parse errors will appear in HTML at the beginning of the file, and analysis of the parent file will not be interrupted. For this reason, the code is in the file must be placed between the regular PHP tags.

  6. #6
    Join Date
    Jan 2008

    Re: How to use include() in PHP?

    I am explaining about the Handling Returns. It is possible to execute a command return () in an include file to finish processing and return to the calling file. Moreover, it is possible to return values from included files. You can take and process the value returned by the function, like any other function. This is not possible when including remote files unless the remote file has valid tags start and end of PHP script. You can declare the needed variables within those tags and will be introduced to where the file was included. Because include () is a special language construct, parentheses are not needed around the argument. Take care when comparing return value.

  7. #7
    Join Date
    Nov 2008

    Re: How to use include() in PHP?

    I have provided you with an example of basic include(). Hope that you can understand better after checking the example :
    PHP Code:
    $fruit 'melon';
    echo "A $color $fruit"
    "A $color $fruit";

Similar Threads

  1. What does KDE 4 desktop include?
    By Bryn in forum Operating Systems
    Replies: 3
    Last Post: 08-11-2010, 06:39 PM
  2. How to Use the #include Directive in ASP?
    By NIcaBoy in forum Software Development
    Replies: 5
    Last Post: 02-02-2010, 06:24 AM
  3. Include explicitly a jsp page in another
    By MAHESA in forum Software Development
    Replies: 5
    Last Post: 02-12-2009, 08:37 PM
  4. How to include files in PHP
    By Samir_1 in forum Guides & Tutorials
    Replies: 2
    Last Post: 01-07-2009, 11:39 AM
  5. include() v/s require()
    By Anikait in forum Software Development
    Replies: 4
    Last Post: 25-03-2009, 10:37 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
Page generated in 1,721,088,217.34549 seconds with 17 queries