0

我的目标是将第一个索引(csv 中每一行的第一个值)放入下拉 htmlselect列表中。

测试.csv

mark, blue, tall,
mike, black, short

索引.php

<?php
$handle = fopen("csv/food.csv", "r");

while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) {
    echo "<pre>";
    print_r($data);
    echo "<pre>";
}
?>

输出

Array
(
    [0] => mark
    [1] => blue
    [2] => tall
    [3] => mike
    [4] => black
    [5] => short
)

如果我在高后删除逗号,则输出

Array
(
    [0] => mark
    [1] => blue
    [2] => tall
mike
    [3] => black
    [4] => short
)

期望的输出

Array
(
    [0][0] => mark
    [0][1] => blue
    [0][2] => tall
    [1][0] => mike
    [1][1] => black
    [1][2] => short
)
4

1 回答 1

2

得到它的工作:

<select name="list" > 
<?php 
$file = fopen("food.csv", "r"); 

while (!feof($file) ) { 
    $lines = fgetcsv($file, 1024);?> 
    <option value="<?php print $lines[0] ?>"> <?php print $lines[0] ?> </option> 
<?php } ?>
</select>
<?php 
fclose($file); 
?>
于 2013-01-02T12:55:19.570 回答