1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Rep Power
    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.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    mymult($int_a, $int_b)
    $ans = $int_a * $int_b;
    return $ans;

    ----------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:


    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    $a = 5;
    $b = 6;
    The answer is : <?php mymult($a, $b); ?>

    ----------end index.php3-------------

    Is my logic right? How about the syntax for example?


  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Niagara Falls (On the wrong side of the gorge)
    Rep Power
    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.

Similar Threads

  1. Replies: 2
    Last Post: August 18th, 2004, 10:45 PM
  2. problems with php includes
    By boseph in forum PHP Development
    Replies: 9
    Last Post: January 23rd, 2004, 04:27 PM
  3. Functions page - php, mysql
    By liberate in forum Project Help Wanted
    Replies: 1
    Last Post: January 22nd, 2004, 11:44 AM
  4. Functions page - php, mysql
    By liberate in forum PHP Development
    Replies: 5
    Last Post: January 19th, 2004, 10:24 PM
  5. Certain functions not working with PHP 4.3.3
    By napoleon_bona_p in forum PHP Development
    Replies: 2
    Last Post: January 14th, 2004, 02:02 AM

IMN logo majestic logo threadwatch logo seochat tools logo