adding functions into php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

marker5a
Forum Commoner
Posts: 29
Joined: Wed May 19, 2004 9:18 pm

adding functions into php

Post by marker5a »

Ok
I just recently discovered how functions work, and man are they great. My question is, instead of having to add

Code: Select all

<?php
function name(){blah blah}
?>
into all of my scripts, is there a way to actually integrate these into the php language itself? In other workds, is there a way to call the function from the script, without actually creating the function in the script itself? Right now, I have a file that contains all of my functions, and at the beginning of my script, i do an 'include' and that incorporates all of the functions into the script. Anyways, please help

Chris
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

either [php_man]include[/php_man], or create your own extension for the functions you wish to have.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

When you say:
In other workds, is there a way to call the function from the script, without actually creating the function in the script itself
then you say:
i do an 'include' and that incorporates all of the functions into the script.
Is this not what you are asking for, or are you asking to call the functions from the actual script itself rather than an external one?
marker5a
Forum Commoner
Posts: 29
Joined: Wed May 19, 2004 9:18 pm

Post by marker5a »

I think what feyd said, creating my own extensions is what I am talking about. Here is an example of what I mean. someone can call the substr command without setting up the function in the script, so I would like to make it so my own functions can just be called from the script. Does that help?

Chris
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Yes I get you now. Say the external script was "script.php" just use:

Code: Select all

include("script.php");
marker5a
Forum Commoner
Posts: 29
Joined: Wed May 19, 2004 9:18 pm

Post by marker5a »

Joe, what I said earlier was that I was using the include, but I wanted to make it so I didnt. Sorry, I know this may be kind of confusing.

CHris
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

require can also be used :D
marker5a
Forum Commoner
Posts: 29
Joined: Wed May 19, 2004 9:18 pm

Post by marker5a »

Joe, I see what you are saying, but I think what feyd was saying earlier was hitting dead on. Don't get me wrong, I appreciate your help, but I think feyd knows what I am talking about.

Chris
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Chris,

feyd is giving exactly what I gave, he wrote:
either include
???
marker5a
Forum Commoner
Posts: 29
Joined: Wed May 19, 2004 9:18 pm

Post by marker5a »

Ok
Im gonna keep sayiong this until one way sounds right. I would like to make it so that I can add functions into php itself. When you download php, it comes with tons and tons of functions, but I want to know how I can add my own to the mix, without creating php files with all of these functions in them.

CHris
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

information on creating extensions: http://www.php.net/manual/en/zend.creating.php
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

OK Well I guess I was way off, lol
marker5a
Forum Commoner
Posts: 29
Joined: Wed May 19, 2004 9:18 pm

Post by marker5a »

well, Feyd and Joe, thanks for the help. I really appreciate it. Im gonna see if I can make some sense out of this from the php site, and if I dont, you know I'll be back. Thanks again

Chris
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Joe wrote:OK Well I guess I was way off, lol
yup ;)
:P
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Yup indeed hehe, I was thinking of something totally different when I wrote that last night!
Post Reply