PDA

View Full Version : including files in php



oskilian
07-01-2002, 07:00 PM
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

Xmevs
07-02-2002, 08:05 AM
I'm not sure I understand what you mean, but to include a php-file inside a php-file, use
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.

oskilian
07-06-2002, 12:05 AM
Thanks, I noticed that

<?php include_once 'myfile.php' ?>

also works

Oskilian

Kelvin
07-06-2002, 06:17 AM
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() (http://www.php.net/manual/en/function.include.php)

Include_once() (http://www.php.net/manual/en/function.include-once.php)

Xmevs
07-06-2002, 10:32 AM
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...)