0
我正在制作一个小型金融市场小部件,使用PHP &HTML。我想将下面的CSV字符串转换为HTML表格将字符串CSV转换为PHP中的HTML表格
result=1&size=200 EURUSD;1.11143;1.11143;1.11170;1.11025;1468549348 CADJPY;82.333;82.345;82.382;81.411;1468549348 EURGBP;0.81374;0.81386;0.83144;0.77313;1466801995 CADCHF;0.76110;0.76110;0.76120;0.75957;1468549347
我在名为$ result的字符串中获取上述值。
我怎样才能显示为像一个标准的HTML表:
符号|出价|询问|高|低|时间
EURUSD | 1.11143 | 1.11143 | 1.11170 | 1.11025 | 1468549348
等..
编辑:
试图
$csvData = $result;
$lines = explode("\n", $csvData);
echo "<table class='display' id='example'><thead >";
echo "<tr class = 'even_gradeC'>
<th class='history'><strong>Symbol</strong></th>
<th class='history'><strong>Bid</strong></th>
<th class='history'><strong>Ask</strong></th>
<th class='history'><strong>High</strong></th>
<th class='history'><strong>Low</strong></th>
<th class='history'><strong>Time</strong></th>
</tr>";
echo "</thead>";
foreach ($lines as $line)
{
$data = explode(';', $line);
if(count($data)==6)
{
echo"<tr class='even_gradeC'>";
foreach($data as $row => $value)
{
if($row<>6)
//{
if ($row==1)
{
echo "<td align='right'>";
echo $value;
echo "</td>";
}
elseif ($row==2)
{
echo "<td>";
echo $value;
echo "</td>";
}
elseif ($row==3)
{
echo "<td>";
echo $value;
echo "</td>";
}
elseif ($row==4)
{
echo "<td>";
echo $value;
echo "</td>";
}
elseif ($row==5)
{
echo "<td>";
echo $value;
echo "</td>";
}
elseif ($row==6)
{
echo "<td>";
echo $value;
echo "</td>";
}
else
{
echo "<td>";
echo $value;
echo "</td>";
}
}
echo "<td>";
echo $value;
echo "</td>";
}
}
echo "</tr>";
echo "</table>";
尝试的东西,回来给我们。堆栈溢出不在这里为你做你的工作。 –
按空格拆分字符串,然后使用“爆炸”作为分隔符 – mulquin
提示:['explode()'](http://php.net/explode) – Darren