Задача была: вывести страницы в HTML по данным строк из CSV (изображения для категорий по заданному признаку - столбец Category Name > все изображения данной категории в списке
Image Source,Category Name,Category HTML,Comma Keywords
/data/catalog/premium-graphics/abstract-flowers/watermark/abstract-flower-bud.png,abstract flowers,abstract-flowers.html "abstract, flower, bud"
/data/catalog/premium-graphics/abstract-flowers/watermark/flower-bud-natural-plant.png,abstract flowers,abstract-flowers.html,"flower, bud, natural, plant"
/data/catalog/premium-graphics/abstract-flowers/watermark/flower-bud-nature.png,abstract flowers,abstract-flowers.html, "flower, bud, nature"
Вопрос: где ошибка в коде — не правильно сформулировано условие или вывод данных в $content?
<?php
function CSVtoHTML() {
$row = 0;
$header = [];
if (($handle = fopen("https://bundlespace.com/graphics/example.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 2565, ",")) !== FALSE) {
// first line is header, grab it then continue
if ( $row === 0) {
$header = $data;
$row++;
continue;
}
$data = array_combine($header, $data);
$category = $data['Category Name'];
$item = '<li><img src="'.Image Source.'" width="200" height="200"></li>';
if (($row[i][$category] == $row[i+][$category])!== TRUE) {
print $item;
$rows++;
}
$item++;
$content = '<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Images in category '.$data['Category Name'].'</title>
</head>
<body>
<h1 id="graphics">Images in category '.$data['Category Name'].'</h1>
<ul>
'.$item.'
</ul>
</body>
<footer>FOOTER</footer>
</html>';
// make the file
$filedata = file_get_contents($content);
$filedata = mb_convert_encoding($content, 'UTF-8');
file_put_contents(''.$data['Category HTML'], $filedata);
$row++;
}
fclose($handle);
}
}
CSVtoHTML();
?>