I want to concatenate two CSV files:
url.csv :
www.text.com/test.html
www.text.com/test1.html
www.text.com/test2.html
color.csv :
Red
Black
Pink
result should like :
www.text.com/test.html?color=Red
www.text.com/test1.html?color=Red
www.text.com/test2.html?color=Red
www.text.com/test.html?color=Black
www.text.com/test1.html?color=Black
www.text.com/test2.html?color=Black
my final code :
$url_csv = "cache_build_urls_file.csv";
$url_csv_resource = fopen($url_csv,"r");
$color_csv = "colors_file.csv";
$color_csv_resource = fopen($color_csv,"r");
$new_color = "color_cache_build_urls_file.csv";
$outputBuffer = fopen($new_color, 'w');
$result = $urls = $colors = array();
if (($handle = fopen($url_csv, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$urls[] = $data[0];
}
fclose($handle);
}
if (($handle = fopen($color_csv, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$colors[] = $data[0];
}
fclose($handle);
}
foreach( $urls as $url ) {
foreach( $colors as $color ) {
$result[] = $url.'?color='.$color;
}
}
foreach($result as $val) {
$arr[0] = $val;
fputcsv($outputBuffer,$arr);
}
fclose($outputBuffer);