/    Sign up×
Community /Pin to ProfileBookmark

Is there a quick way to include a standard set of functions defined externally? I’ve defined a few functions and I will need them for several different scripts and don’t want to have to copy and paste them to each script.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pointfiftyaeAug 06.2005 — make a file called functions.php (for example) where you write your functions within <?php and ?> tags, and then use include('path/to/functions.php'); or require(...); in the pages that need these functions.

This should do.
Copy linkTweet thisAlerts:
@agent_x91authorAug 06.2005 — k i had a feeling it was something like that, I've seen include() used before.
Copy linkTweet thisAlerts:
@pointfiftyaeAug 06.2005 — In this case I'd use require(), since it will stop the execution of the code if the indicated file doesn't exist or if there is an error. Useful for a self-defined functions list.
×

Success!

Help @agent_x91 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...