CWD
05-20-2006, 03:58 AM
:thumbsup: I'm trying to figure out how to handle extracting vars from $_POST array and then formatting them to be written to a text file that can in turn be read by the flash file that submitted the $_POST in the first place.
The vars will need to be generated from expressions because there will not always be the same number of vars. The vars will be in sets of 3 like this:
$expire_1
$recipient_1
$request_1
$expire_2
$recipient_2
$request_2
etc etc etc
There could be anywhere from 0-100 sets of these vars at any given time.
They will need to be formatted like this for writing to the text file so my flash file can read the file:
&expire_1=value&
&recipient_1=value&
&request_1=value&
&expire_2=value&
&recipient_2=value&
&request_2=value&
etc etc etc
I am thinking that something like this code may be heading in the right direction for defining the variables after they are extracted from the $_POST array:
for ($i=0, $j=1; $j <= var_entries; $i++, $j++) {
${"expire_{$j}"} = $_POST['expire_'.$i];
$i++;
${"recipient_{$j}"} = $_POST['recipient_'.$i];
$i++;
${"request_{$}j"} = $_POST['request_'.$i];
}
}
I need help :confused: with this code above as I doubt that I have valid code [trying to adapt Action Script to PHP through studying examples on this board, in the php manual and in some books I have].
I also need help with understanding how I would adapt the following code to write the vars to the text file using a "var_entries" variable in the $_POST array so I can generate the right number of var sets
if(is_writable('request.txt'))
{
$fp = fopen(request.txt','w');
$content = "&".$expire_1."&\n&".$recipient_1."&\n&".$request_1."&\n" //etc etc;
fwrite($fp,$content);
fclose($fp);
}
else
{
echo'File is not writable';
}
Where I'm stumped on this code is how to create the proper string for the $content var -- can I use another for loop for this somehow?
The vars will need to be generated from expressions because there will not always be the same number of vars. The vars will be in sets of 3 like this:
$expire_1
$recipient_1
$request_1
$expire_2
$recipient_2
$request_2
etc etc etc
There could be anywhere from 0-100 sets of these vars at any given time.
They will need to be formatted like this for writing to the text file so my flash file can read the file:
&expire_1=value&
&recipient_1=value&
&request_1=value&
&expire_2=value&
&recipient_2=value&
&request_2=value&
etc etc etc
I am thinking that something like this code may be heading in the right direction for defining the variables after they are extracted from the $_POST array:
for ($i=0, $j=1; $j <= var_entries; $i++, $j++) {
${"expire_{$j}"} = $_POST['expire_'.$i];
$i++;
${"recipient_{$j}"} = $_POST['recipient_'.$i];
$i++;
${"request_{$}j"} = $_POST['request_'.$i];
}
}
I need help :confused: with this code above as I doubt that I have valid code [trying to adapt Action Script to PHP through studying examples on this board, in the php manual and in some books I have].
I also need help with understanding how I would adapt the following code to write the vars to the text file using a "var_entries" variable in the $_POST array so I can generate the right number of var sets
if(is_writable('request.txt'))
{
$fp = fopen(request.txt','w');
$content = "&".$expire_1."&\n&".$recipient_1."&\n&".$request_1."&\n" //etc etc;
fwrite($fp,$content);
fclose($fp);
}
else
{
echo'File is not writable';
}
Where I'm stumped on this code is how to create the proper string for the $content var -- can I use another for loop for this somehow?