Hi,
Like
stakadush said, you can use your function in many pages. However, to do that you have to use one of these statements BEFORE you call your own (external) functions:
[tt]include 'myFunc.php'; or include('myFunc.php');[/tt]
-loads the external file
multiple times if the same include() statement is used or called multiple times.
-displays a
warning if the external file is not found but
continues the script.
[tt]include_once 'myFunc.php'; or include_once('myFunc.php');[/tt]
-loads the external file
only once, even if the same include() statement is used or called multiple times.
-displays a
warning if the external file is not found but
continues the script.
[tt]require 'myFunc.php'; or require('myFunc.php');[/tt]
-loads the external file
multiple times if the same require() statement is used or called multiple times.
-displays a
fatal error if the external file is not found, hence,
aborting execution of your script.
[tt]require_once 'myFunc.php'; or require_once('myFunc.php');[/tt]
-loads the external file
only once, even if the same require_once() statement is used or called multiple times.
-displays a
fatal error if the external file is not found, hence,
aborting execution of your script.
Also, if one of the above statement is used in a conditional block - like [tt]
if($something)[/tt] - you have to put the statement in a block -ie. curly brackets [tt]
{}[/tt].
Here's an example I wrote to illustate how to do it:
Filename : main.php
Code:
<?
$user = "Me";
$dbug = false;
if($dbug) {
include('dbug.php');
} else {
include('myFunc.php');
}
info($user);
echo "This is PHP talking ...";
?>
Filename : myFunc.php
Code:
<?
function info($name) {
echo "Hi $name! -You're working in <B>normal</B> mode.<BR>\n";
}
?>
Filename : dbug.php
Code:
<?
function info($name) {
echo "Hi $name! -You're working in <B>debug mode</B>.<BR>\n";
}
?>
Notice that the external php scripts must be wrapped in <? and ?>
Good luck with it §;O)
Jakob