1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| $file = "csv.csv";
$tbody = '';
$hsc = function($p) { return htmlspecialchars($p, ENT_QUOTES, 'utf-8'); }; // échappement des caractères
if (($fh = fopen($file, 'rb')) !== false)
{
$even = true;
while (($data = fgetcsv($fh, 1024, ';')) !== false)
{
$color = ($even) ? 'sombre' : 'clair';
$even = ! $even;
$tbody .= <<<html
<tr>
<td class="{$color}" align="center">{$hsc($data[0])}</td>
<td class="{$color}" align="center"><a href="{$data[1]}">{$hsc($data[1])}</a></td>
</tr>
html;
}
}
echo <<<html
<table border="1" align="center" style="width:80%; bordercolor:#000040;">
<tbody>{$tbody}</tbody>
</table>
html; |
Partager