这是我的代码,输出和疑问......
<?php
$csvData = file_get_contents("http://feed2.abc.com/PriceWs/PriceSnap.asmx/PriceUpdate?item=GC-APR16,SI-MAY16,PA-JUN16,PL-APR16,CL-APR16,BRCL-MAY16,NG-APR16,HO-APR16,HG-MAY16,CC-MAY16,KC-MAY16,CN-MAY16,CT-MAY16,WH-MAY16,SB-MAY16,SY-MAY16,BO-MAY16,&col=last,bid,ask,high,low");
$lines = explode(PHP_EOL, $csvData);
$array = array();
foreach ($lines as $line) {
$array[] = str_getcsv($line);
}
foreach($array as $k=>$v){
?>
<table border="1">
<tr>
<td> <?php echo $v[0]; ?><td>
<td> <?php echo $v[1]; ?><td>
<td> <?php echo $v[2]; ?><td>
</tr>`enter code here`
<?php
}
?>
输出就像这样:
GC-APR16 1234.40 1233.30
SI-MAY16 15.180 15.180
PA-JUN16 538.10 539.10
PL-APR16 954.50 955.60
HG-MAY16 2.0750 2.0745
CC-MAY16 2851.0 2849.0
KC-MAY16 119.90 119.90
CN-MAY16 361.75 361.50
CT-MAY16 59.44 59.42
WH-MAY16 460.25 460.00
SB-MAY16 14.33 14.33
SY-MAY16 905.00 905.00
BO-MAY16 33.87 33.86
INSTEAD OF GC-APR16需要显示“GOLD”,SI-MAY16需要显示“SILVER”
请帮助......
非常感谢
答案 0 :(得分:0)
$v[0] = GC-APR16 1234.40 1233.30';
// get first two chars
$two_chars = substr($v[0]);
// "multi if-else"
switch($two_chars) {
case 'GC': $new_tx = 'GOLD'; break;
...
default: ; //show error
}
echo $new_tx;