使用Excel行中的占位符创build多个html文件

我想从Excel电子表格的每一行创build多个HTML文件

Excel电子表格:

+-------+----------------+--------------+ | Name | Phone | Description | +-------+----------------+--------------+ | James | 01234 5678910 | Text | | Clare | 16771 9432772 | Text | | Mike | 08001 7745396 | Text | +-------+----------------+--------------+ 

我创build了一个包含占位符的“模板”HTML文件,例如:

  <div style="width:100%"> {name} {phone} {description} </div> 

我想使用名称列作为文件名,并将该行的每个单元格保存到HTML模板中的占位符。

代码执行完成后,应该在{placeholder}部分创build名为“James.html”,“Clare.html”,“Mike.html”等的文件。

我试图尝试使用CSV文件,但它没有工作….这是我的CSV / PHP代码:

 <? $base_template = file_get_contents('/template.html'); $file_to_read = '/sample.csv'; ini_set("auto_detect_line_endings", 1); $filename = ''; if (($handle = fopen($file_to_read, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $name = $data[0]; $address = $data[1]; $description = $data[2]; $filename = preg_replace('/[\s\W]+/','',$name); $filename = substr($filename, 0, 10); $template = str_replace('{name}', $name, $base_template); $template = str_replace('{phone}', $phone, $template); $template = str_replace('{description}', $description, $template); $file = fopen('/save/'.$filename.'.html',"w+"); fwrite($file, $template); fclose($file); } fclose($handle); } ?> 

如果有人有任何build议,将是伟大的! 谢谢