Re: Mixing Arrays

From: Date: Tue, 15 Apr 2003 11:04:46 +0000
Subject: Re: Mixing Arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-143906@lists.php.net to get a copy of this message
Webmaster wrote:
Anybody out there that can help me with this one? Have the following form posting arrays to a text file : <form method="post" action="prod.php"> <input type="text" name="prodid[ ]" size="7"> is it working with the spaces between the square brackets?
<input type="text" name="proddes[ ]" size="35"> <input type="text" name="prodid[ ]" size="7"> <input type="text" name="proddes[ ]" size="35"> <input type="text" name="prodid[ ]" size="7"> <input type="text" name="proddes[ ]" size="35"> ... and so on <input type="submit" value="Submit"> prodid is the Product ID and proddes is the Product Description On prod.php I have : // $data1 = join("%", $prodid); // $data2 = join("%", $proddes); // $main_data = "$data1" . "$data2"; $main_data=array();
foreach($_POST['prodid'] as $i => $prodid) { $main_data[]=$_POST['prodid'][$i] .'%'. $_POST['proddes'][$i]; } $main_data=join('%',$main_data);
$fh = fopen("products.txt", "w"); if (!$fh) {
    die("<br>Failed to open file");
} fwrite($fh, "$main_data"); fclose($fh); this generates the output in the textfile as: 1%2%3%Product One Description%Product Two Description%Product Three Description Question is - how do I get the script to write to the text file so that I have a result that looks like this: 1%Product One Description%2%Product Two Description%3%Product Three Description Any help will be appreciated! - Thanx August Kupke


« previous php.general (#143906) next »