random1 Posted November 23, 2007 Share Posted November 23, 2007 Hi all, I'm a mid-level PHP developer and I'd like to know if it's possible to create global functions in PHP. i.e. functions that are available to ALL pages (included and required ,php files too) in the website. I currently have a require() function working to force include a .php file with a call to a function but instead of triggering the function it simply prints out: generateLink("http://www.google.com", "lnk_google", "Go to Google", "_blank", "", "This link takes you to Google in a new window"); Am I taking the wrong approach? ??? Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 23, 2007 Share Posted November 23, 2007 Put your functions in a functions.php file. Then include_once("path/to/functions.php"); The functions will be available to any script that includes it. PhREEEk Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2007 Share Posted November 23, 2007 You would need to post your code to get specific help with what it is doing. My guess is that you are missing some <?php and ?> tags somewhere. Quote Link to comment Share on other sites More sharing options...
random1 Posted November 23, 2007 Author Share Posted November 23, 2007 Thanks for the quick replies. I have an "index.php" page requires() an included file called "inc_functionspagecreation.php". "index.php" (a template page) then requires a page called "home.php". I'd like "home.php" to have full access to functions in "inc_functionspagecreation.php". Quote Link to comment Share on other sites More sharing options...
hostfreak Posted November 23, 2007 Share Posted November 23, 2007 If the inc_functionspagecreation.php is included to index.php and home.php is included to index.php, home.php should have access to all the functions in inc_functionspagecreation.php If it is just printing it out as text then for some reason the php engine isn't parsing it; which is most likely do to a missing php tags <?php ?> (as PFMaBiSmAd suggested). However, without posting the relevant code(s), there is no way for us to tell. Right now were just poking around in the dark... Quote Link to comment Share on other sites More sharing options...
random1 Posted November 23, 2007 Author Share Posted November 23, 2007 Thanks, it was hidden away from me. Simply needed closing %> Quote Link to comment Share on other sites More sharing options...
hostfreak Posted November 23, 2007 Share Posted November 23, 2007 Any particular reason why you are using ASP style tags? It is always recommended to use the standard tags: http://www.php.net/manual/en/language.basic-syntax.php (See: Example 10.2. PHP Opening and Closing Tags) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.