Re: puzzled ?? - second edition
| From: | Gorka Valencia | Date: | Sun, 01 Oct 2000 20:59:33 +0000 |
| Subject: | Re: puzzled ?? - second edition | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18220@lists.php.net to get a copy of this message | ||
hi,
sorry for my poor written english.
I've found a solution for your problem, and this is the code:
/*---------------------- (begin) LOOP.php3 --------------------*/
<?php
if (!$i) {
$i = (int)$argv[1];
}
if ($i > 0){
$i--;
print "hello , this is round $i<br>";
exec("php -q loop.php3 $i", $result_array);
print "$result_array[0]<BR>";
}
else exit();
?>
/*---------------------- (end) LOOP.php3 --------------------*/
-.-.-.-.-. you use this query on the browser: loop.php3?i=9 .-.-.-.-.-
You will need to execute the php script by calling the PHP interpreter, so the
line you wrote as "exec("loop.php3?i=$i", $result_array);" would look like this:
>>>
exec("php -q loop.php3", $result_array); <<<
Note the "-q" parameter, which means silent mode, or "do not write the html
header information. If not included, the header info will be written each time
the script is called.
The script will then generate the $result_array, where it will write the output
(print)... If you only write one line, you will only need to get the fist array
element (0), but if you generate multiple lines, the you'll need to process all
of them.
It may seem very dificul to understand first. I will explain the code later if
you wish, cause this email is getting too large!
I would also recommend you to use a simple recursive funtion to do the same.
Something like this:
/*------------- loop.php3 -------------------------*/
<?php
function loop_recursive($i) {
if ($i > 0) return 1;
else {
echo "hello , this is round $i<br>";
loop_recursive(--$i);
}
}
loop_recursive($i);
?>
/*------------ loop.php3 ------------------------*/
hope this will help you!
Regards,
Gorka Valencia
peter strzygowski wrote:
>
> as a follow-up to sonias problem:
>
> i´m trying nearly the same thing for some days now,
> but i want to call a php-script from within itself - a loop.
>
> I want to do a call loop.php3?i=9
> and with the loop.php3:
> -------- loop.php3 ---------------------
> <? if ($i > 0){
> $i = $i -1;
> exec("loop.php3?i=$i", $result_array);
> echo "hello , this is round $i<br>";
> };
> ?>
> -------------------------------------------------
>
> I expect to see lines of text, but i get only 1 ! ??
>
> perhaps anyone did know how to manage it?
>
> thanks
> peter strzygowski
>