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

    Join Date
    Feb 2000
    Posts
    43
    Rep Power
    15
    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


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

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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, 11:45 PM
  2. problems with php includes
    By boseph in forum PHP Development
    Replies: 9
    Last Post: January 23rd, 2004, 05:27 PM
  3. Functions page - php, mysql
    By liberate in forum Project Help Wanted
    Replies: 1
    Last Post: January 22nd, 2004, 12:44 PM
  4. Functions page - php, mysql
    By liberate in forum PHP Development
    Replies: 5
    Last Post: January 19th, 2004, 11: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, 03:02 AM

IMN logo majestic logo threadwatch logo seochat tools logo