我以前从未使用过cvs,所以请耐心等待。
我用下面的代码干净利落地打印出来。现在,我想要做的是,这个文件的4列包含一个数字。我希望能够将该数字或实际单元格2-4链接到与该数字相对应的图像。
(即/ XHS2 /2.jpg的图像链接/ PNM3 /3.jpg...)
我能这么做吗?
实际页面:I want to be able to link each line/the "code" section to a lightbox photo
<?Php
echo "<html><body><table border=1>";
$f = fopen("file.csv", "r");
$fr = fread($f, filesize("file.csv"));
fclose($f);
$lines = array();
$lines = explode("\r\n",$fr); // IMPORTANT the delimiter here just the "new line" \r\n, use what u need instead of...
for($i=0;$i<count($lines);$i++)
{
echo "<tr>";
$cells = array();
$cells = explode(",",$lines[$i]); // use the cell/row delimiter what u need!
for($k=0;$k<count($cells);$k++)
{
echo "<td>".$cells[$k]."</td>";
}
// for k end
echo "</tr>";
}
// for i end
echo "</table></body></html>";
?> 发布于 2013-06-13 23:55:51
由于不是100%的CSV结构,以及您到底想要实现什么,首先,您可以使用原生PHP命令来解析CSV文件,例如str_getcsv或fgetcsv,从而使您的工作变得更容易。获得数组后,从第四个元素中解析数字(或者从第二个元素中解析?这在问题中并不清楚),并将其添加到您的图像url中,如下所示:
$url = 'image_path/' . $your_number . '.jpg';
https://stackoverflow.com/questions/17091476
复制相似问题