define function from other files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ju-Pao
Forum Newbie
Posts: 9
Joined: Wed Feb 21, 2007 3:44 am

define function from other files

Post by Ju-Pao »

Is there a way in PHP to use the define function from another file in another directory in your PHP code?

For example my code is in this directory /home/dirA/dirB/dirC/

the the define function was from the directory /home/dirA/
define('KEYWORD',boi);

how can i use it in my code so that if I echo KEYWORD, it will display boi
without putting the define function in my code.

thank you guys for your help
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Or include(). They're not the same.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

you'll have to include() the file - you can alternatively add this to every file using "auto_prepend_file" in php.ini
User avatar
Ju-Pao
Forum Newbie
Posts: 9
Joined: Wed Feb 21, 2007 3:44 am

Post by Ju-Pao »

thanks for the reply guys,

additional question how can I include a file from a different directory?

I use include_path='.:/var/www/html/dir1';

but it doesn't seem to work or it is not what I need
I already figured it out

just to share, I use include("/dir/somefile.txt");


:D I never thought it was this simple, hehehe
Post Reply