我看过类似的问题,但我无法将它们与我的问题联系起来。 如何将此字符串转换为表格格式的打印数组?或者如何在表格中打印此字符串,其中包含参考编号,客户编号,合同编号,顺序,交易编号,传输日期,状态,响应代码,收集的金额,下次尝试日期,客户成本,不包括客户成本的金额表格标题和表格的其余数据。
参考编号,客户编号,合同编号,顺序,交易编号,传输日期,状态,响应代码,收集金额,下次尝试日期,客户成本,Amout不包括客户成本2518750,2,2,1,22439195 ,2014-11-19 10:31:56,成功,00,5.00 ,, 0.00,5.00 2518753,GK000001,M8PAY004,1,22439198,2014-11-19 10:58:27,成功,00,189.99,,0.00, 189.99 2518754,GK000001,M8PAY004,1,22439199,2014-11-19 11:00:39,成功,00,99.99,0.00,99.99 2518755,GK000001,GK000001,1,22439200,2014-11-19 11:17 :08,成功,00,30.00 ,, 0.00,30.00 2518756,GK000001,M8PAY004,1,22439201,2014-11-19 11:21:48,成功,00,189.99 ,,, 0.00,189.99 2518757,GK000001,M8PAY0041,1, 22439202,2014-11-19 11:39:53,成功,00,299.99 ,,, 0.00,299.99 2518758,GK000001,M8PAY004,1,22439203,2014-11-19 12:16:13,成功,00,299.99 ,, 0.00,299.99 2518759,GK000001,PM8PAY004,1,22439204,2014-11-19 12:43:49,成功,00,189.99,,0.00,189.99 2518760,GK000001,M8PAY004,1,22439205,2014-11-19 13:14:07,失败,56,0.00 ,, 0.00,0.00 2518761,GK 000001,PM8PAY004,1,22439206,2014-11-19 13:14:31,失败,56,0.00,,0.00,0.00 2518762,GK000001,GK000001,1,22439207,2014-11-19 13:17:07,成功,00,30.00 ,, 0.00,30.00 2518763,GK000001,M8PAY004,1,22439208,2014-11-19 13:20:39,失败,56,0.00 ,, 0.00,0.00 2518764,GK000001,M8PAY004,1,22439209 ,2014-11-19 13:23:16,失败,56,0.00 ,, 0.00,0.00 2518765,GK000001,M8PAY004,1,22439210,2014-11-19 13:24:31,成功,00,189.99,,0.00, 189.99
这是我正在使用的网络服务的回复。我尝试使用explode函数,但它给了我一个数百个元素的数组。
感谢您的帮助。
答案 0 :(得分:0)
你提到了字符串,所以用这个很容易:
<table>
<?php
$content = "Reference Number,Client Number,Contract Number,Sequence,Transaction Number,Transmission Date,Status,Response Code,Amount Collected,Next Attempt Date,Cost To Client ,Amout Excluding Cost To Client
2518750,2,2,1,22439195,2014-11-19 10:31:56,Successful,00,5.00,,0.00,5.00
2518753,GK000001,M8PAY004,1,22439198,2014-11-19 10:58:27,Successful,00,189.99,,0.00,189.99
2518754,GK000001,M8PAY004,1,22439199,2014-11-19 11:00:39,Successful,00,99.99,,0.00,99.99";
$lines = explode("\n", $content);
foreach ($lines as $line) {
$pieces = explode(",", $line);
echo '<tr>' . "\n";
foreach ($pieces as $piece) {
echo '<td>' . trim($piece) . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
?>
</table>
如果你的内容是字符串,因为caCtus很难过,你可以使用fgetcsv
函数。
注意:如我所见,属性的数量和数据的数量不匹配。