c-o-d-e Posted December 26, 2009 Share Posted December 26, 2009 If I have a file - functions.php with "function checkit()" Within index.php page I include functions.php How would I call the fuction in index.php? Surely just saying "function checkit()" in the middle of no where is going to look a bit odd? Quote Link to comment https://forums.phpfreaks.com/topic/186388-how-do-i-call-a-function-which-is-set-in-another-page/ Share on other sites More sharing options...
rajivgonsalves Posted December 26, 2009 Share Posted December 26, 2009 if you included function.php you just call the function, I don't exactly understand what you mean by odd checkit(); Quote Link to comment https://forums.phpfreaks.com/topic/186388-how-do-i-call-a-function-which-is-set-in-another-page/#findComment-984282 Share on other sites More sharing options...
Psycho Posted December 26, 2009 Share Posted December 26, 2009 Yes it is just that simple. When you "include" a php file in another it is almost exactly the same as if the code from the included file was written in-line to where it was included. Quote Link to comment https://forums.phpfreaks.com/topic/186388-how-do-i-call-a-function-which-is-set-in-another-page/#findComment-984284 Share on other sites More sharing options...
c-o-d-e Posted December 26, 2009 Author Share Posted December 26, 2009 Hmm ok. Odd = empty, it doesn't look like its right, or fits in. Though if it's correct, I wont complain. In a function, you'd have.. return true, return false. What would that look like in index.php for function checkit() ? Quote Link to comment https://forums.phpfreaks.com/topic/186388-how-do-i-call-a-function-which-is-set-in-another-page/#findComment-984285 Share on other sites More sharing options...
.josh Posted December 26, 2009 Share Posted December 26, 2009 do you know how to use functions? You use them the exact same way here...including a script in another script is pretty much for all intents and purposes the same as just cut-pasting the stuff in the main script. Example: functions.php function makeBold($string) { return "<b>" . $string . "</b>"; } index.php include ('functions.php'); echo makeBold('hello'); // or $string = makeBold('hello'); echo $string; Quote Link to comment https://forums.phpfreaks.com/topic/186388-how-do-i-call-a-function-which-is-set-in-another-page/#findComment-984292 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.