Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在通过php使用CSV数据的表中设置列的样式_Php_Html_Csv - Fatal编程技术网

在通过php使用CSV数据的表中设置列的样式

在通过php使用CSV数据的表中设置列的样式,php,html,csv,Php,Html,Csv,我正在寻找样式我的表列例如,使作者列显示例如“书名”在粗体红色,而在斜体蓝色等价格 2012-03-11,paul,the book title,386,10,256 我的php代码 echo "<table cellspacing='0' cellpadding='0'> \n\n <thead> <tr> <th>Date</th> <th>Author</th> <th>Title<

我正在寻找样式我的表列例如,使作者列显示例如“书名”在粗体红色,而在斜体蓝色等价格

2012-03-11,paul,the book title,386,10,256
我的php代码

echo "<table cellspacing='0' cellpadding='0'>   \n\n
<thead>
<tr>
<th>Date</th>
<th>Author</th>
<th>Title</th>
<th>Prices</th>
<th>Sales</th>
<th>Rank</th>
</tr>
</thead>";
$f = fopen("local/bookdata.csv", "r");
$i = 0;

while (($line = fgetcsv($f)) !== false) {
     echo "<tr class='$class".(($i%2)?'odd':'even')."'>";
        foreach ($line as $cell) {
                echo "<td style='font-weight: bold;'>" . htmlspecialchars($cell) . "</td>";
        }
        echo "</tr>\n";
    $i++;
}

fclose($f);
echo "\n</table>";
echo”\n\n
日期
作者
标题
价格
销售额
等级
";
$f=fopen(“local/bookdata.csv”,“r”);
$i=0;
而(($line=fgetcsv($f))!==false){
回声“;
foreach($行作为$单元格){
echo“.htmlspecialchars($cell)”;
}
回音“\n”;
$i++;
}
外国法郎(f美元);
回音“\n”;
欢迎任何帮助

php

$classes = array('', '', 'title', 'price' , '', '');
// ...
foreach ($line as $idx=>$cell) {
    echo "<td class='{$classes[$idx]}'>". htmlspecialchars($cell) . "</td>";
}

别忘了那些好的老朋友!tr:n个孩子(偶数){背景:#CCC}tr:n个孩子(奇数){背景:#FFF}
td.title { font-weight: bold; color: red; }
td.price { font-style: italic; color: blue;  }