RE: #include + global functions

From: Date: Sun, 04 Jun 2000 18:22:21 +0000
Subject: RE: #include + global functions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-984@lists.php.net to get a copy of this message
You have several problems. Missing } in the function #include "include.php"; should be include "include.php"; You almost never see a print or echo in a function. This is a better way to do the same thing. ##include.php## <?php function test() { $text= "This is a test function.<br>\n"; //echo "This is a test function.<br>\n"; return($text); } ?> ##script.php## <?php include("include.php"); print test(); //test(); ?> Something I learned the hard way about return. Return() passes the variable back to the function you are calling. print test(); works print $text; does not work print $text; will work if you make $text GLOBAL in the function instead of using return. Ted Knudson http://www.automatedcabinets.com http://www.pulsarusa.com > > I'm having trouble getting #include to work like I want it to. I want > to have a file that contains a bunch of functions and variables. When > I #include this file, I want the functions and variables contained > within to be accesible in my script. Here's what the external file > looks like: > > ##include.php## > <? > function test() > echo "This is a test function.\n"; > } > ?> > > And here's what my script looks like (let's say): > > ##script.php## > <? > #include "include.php"; > > test(); > ?> > > How can I make this work? > > >

« previous php.general (#984) next »