打印 txt 列的元素

Print the elements of a txt column

得到这个代码php

$data ='
one;uno
two;dos
three;tres
four;cuatro
'

我想打印一行中的第一列,用逗号和空格分隔元素,以获得这个结果:

one, two, three, four

有什么帮助吗?我正在这样做,但我做不到:

<?php

$data ='
one;uno
two;dos
three;tres
four;cuatro
';

$line = explode("\n", $data);
for($i = 0; $i<count($line); $i++) {        

$item = explode(";", $line[$i]);

$coma = implode(', ', $item[0{);

echo $coma;

}
?>

试试你的代码的这个修改版本

$data ='one;uno
two;dos
three;tres
four;cuatro';
$coma=array();
$line = explode("\n", $data);

for($i = 0; $i<count($line); $i++) {        
$item = explode(";", $line[$i]);
$coma[]=  $item[0];
}

echo implode(',',$coma);