April 7th, 2000, 05:48 AM
-
I may be off in left field here, but please hold your personal chuckles enough to humiliate me publicly 
I have a few routines that I use on my site regularly, and in several places. I would like to be able to write my own functions and store them elsewhere so I can just call the function rather than re-write the whole routine everytime it is used in a different page.
Here's my mentality, correct me if I'm wrong.
I'm thinking I'm supposed to create a file like myfunctions.php3, that would house all my functions.
Example:
-----------myfunctions.php3---------
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
mymult($int_a, $int_b)
{
$ans = $int_a * $int_b;
return $ans;
}
[/code]
----------end myfunctions.php3--------
(I know thats so basic, and useless, but its just for example)
Then in my .php3 page on my site, I'm thinking I need to put something like:
----------index.php3------------------
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<?php
require('/home/site/www/myfunctions.php3')
$a = 5;
$b = 6;
?>
The answer is : <?php mymult($a, $b); ?>
[/code]
----------end index.php3-------------
Is my logic right? How about the syntax for example?
Thanks,
Mike
April 7th, 2000, 07:54 AM
-
1 problem but I'm sure it's just because it's an example. Your forgot the function keyword in your function definition.
Otherwise, assuming the path to the included file is correct, yes that will work. This is a very common practice.