php: how should I go about sending info to a script and then using the result from it within another script?

dpopiz

Diamond Member
Jan 28, 2001
4,454
0
0
I'm trying to figure out how I can do this or something like it.
let's say I have script A:

<?php

$input = "something"

//somehow call the somefunc() function from this script (I don't know how)

echo(somefunc($input));

?>


and script B:

<?php

function somefunc($input)
{
$output = $input." else";
return $output;
}

?>



so then the html output from script A should be:

something else


I tried doing include("scriptB.php?input=something"); but that just includes the php code for script B, not the output it generates. I could do that and then call the function after that code has been added to script A.
but that's what I'm trying to avoid. script B is very very large, so I don't want it to be loaded into the calling script first. I also want to keep functions a little bit more orgainzed in this fashion: by breaking them up among multiple scripts.

I was thinking maybe there's some way to do this sort of thing with http get....or some php thing I'm not aware of.

have any ideas?
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,674
146
106
www.neftastic.com
If you're passing info back and forth between seperate "pages", then you have to POST or GET the data across to the pages. Basically what you would do is Script A would call Script B with:

http://www.yoursite.com/ScriptB.php?input=something

Then Script B would handle whatever it's supposed to handle and call back on exit with:

http://www.yoursite.com/Script...rScriptAdidtosomething

Then Script A would key off the fact that there's a $result variable and run that branch of an IF block.

That seems to be what you want it to do. But an easier way is to simply have somefunc() RETURN a result, and in your script:

<?PHP
require("ScriptB.php")

$input = "something"
$result = somefunc($input)

// then use $result
?>

Either way, I think this is what you need.
 

JaakRandmets

Junior Member
Aug 27, 2004
17
0
0
okay, you have 2 files:
script A and script B

A.php:
<?php
require_once("B.php"); //inclues file B.php to A.php, note you get function fubar from the second file
$someval = 1; //assignes 1 to val
echo fubar($someval); //1 as input to function and echos out value retured by fubar()
?>

B.php
<?php
function fubar($input) //1 as input
{
$output = 1337 * $input; //multiplies inout with 1337
return $output; //and outputs the multiplication
}
?>

asap :)

is this what you mean?
or you interested in $_REQUIRE / $_POST / etc. arrays? (forms), your problem is quite cryptic
 

Templeton

Senior member
Oct 9, 1999
467
0
0
If you want to use a function of script b from script a, you'll need to load the contents of script b completely using an include or require. If script b is so massive in size that it'll slow down execution of script a, then you should consider breaking it down into multiple files each containing related functions. Trying to capture the output generated by script b will in every case be slower then just including all of script b from script a - either way script b needs to be parsed/interpreted.