View Full Version : Calling a PHP file inside a function

07-29-2011, 09:00 AM
Ok... still very new to PHP so bear with me... might not explain this quite right.

I am trying to take the output from another php file and use it to change the value of the status variable within a multi-dimensional array. So for every member of that array, I would like to be able to check the operatorstatus.php take its output and associate it with the appropriate status.

The problem I am having is that I am unsure how to call that file within the function, save its output to a variable, and then use either an if/else statement or case statement to change each members status based on the value of the returned variable. If anyone could point me in the right direction as to what syntax to use, it would be greatly appreciated.

07-29-2011, 09:31 AM
You can use ob_start (http://www.php.net/ob_start), ob_get_contents (http://www.php.net/manual/en/function.ob-get-contents.php) and ob_get_clean (http://www.php.net/manual/en/function.ob-end-clean.php).
ps. I suggest you to use a function instead of checking the file output.

07-29-2011, 09:40 AM
I'll take a look at those and see what I can do, thank you.

The operator.php file is really just a function in and of itself. The output of that should be either ./images/away.gif or ./images/available.gif

So either of those values would be what I would be checking against. I do intend on eventually creating a single php file that does everything that the two of these do. And that would rely on using functions as you recommend.

07-29-2011, 09:50 AM
The simplest way is to return a value from within your function.

07-29-2011, 12:58 PM
I went through and combined the two php files. Made the process much easier. Thanks!