-1
我確實有一個名稱,年齡,類型,地址,電話&郵件和大約50行數據的五列的電話列表。數據採用csv格式(文件:my_data.csv)。從csv的php separte行
NAME AGE TYPE ADDRESS PHONE Email
Robert 36 Freind CA Avenue, jercy street, Machigon 3456231 [email protected]
Calux 24 Lover new opera, bank steet,Machigaon 3456760 [email protected]
Gandy 25 Lover Ninth house, dark square, machigaon 3458923 [email protected]
對於我的項目,我將csv與php連接起來,我的php文件是:get-add.php。 下面的源代碼中給出:
<?php
$check="Lover"; // to be checked in the third column
$handle = fopen("my_data.csv","r")or die("file dont exist");
$output = '';
while (!feof($handle)){
$data = fgetcsv($handle,2096,",");
if(($data[2] ==$check)){
$output .= sprintf("%s; Age: %d; %s; %s; Ph:%d; Mail: %s)<br>",
$data[0], $data[1], $data[2], $data[3], $data[4], $data[5]);
}
}
echo $output;
fclose($handle);
?>
,結果進來如下因素格式。
Calux; Age:24; Type:Lover new opera, bank steet,Machigaon; Ph:3456760; Mail:[email protected]
Gandy Age:25; Type:Lover; Ninth house, dark square, machigaon; Ph:3458923; Mail:[email protected]
雖然我需要以下格式。
Calux Age:24; Lover
new opera, bank steet,Machigaon
Ph:3456760
Mail: [email protected]
Gandy Age:25; Lover
Ninth house, dark square, machigaon
Ph:3458923
Mail: [email protected]
請幫助朋友們糾正php代碼。