|
Posted by JP on 11/29/07 19:01
Folks,
Real newbie here. I'm going through some tutorials and reading as much
as possible to learn PHP.
This is a simple question.
I want to put a bunch of PHP functions into a file. These functions
would be shared by a lot of different php scripts.
I want to then include() or include_once() that file with the defined
functions into each php script.
The problem I'm having is that instead of including the file and thus
defining the functions within my main script, the included files are
being displayed as text.
I read the following in a beginners tutorial named "Including Files in
PHP - Beginner Tutorial" on the phpfreaks.com site
"If you include a file, for example a plain text file that does not
have the PHP open and close tags, the file will be displayed within
the current PHP script."
So I guess I'm confused.
If I create my include file (lets call it functions.php)
<?php
function testfunct1 ($text)
{
echo "Received text " . $text . "\n";
}
?>
And then if I create the main script (lets call it main.php)
<?php
include ('functions.php');
?>
I get an error because basically, I'm nesting <?php ?> tags.
If I take out the <?php ...?> tag from within functions.php, then
instead of including the function definition in main.php, the contents
of functions.php is displayed when main.php runs.
What the heck am I missing here?
Thanks in advance!
Navigation:
[Reply to this message]
|