2015-01-13 3 views
0

고객 세부 정보가 100,000 개의 큰 csv 파일 하나가 있습니다. 내 안드로이드 응용 프로그램 용 데이터를 가져오고 싶습니다. CSV 파일에서 특정 행을 읽으 려합니다. 처럼 나는 고객의 모든 세부 사항을 원한다 cust_id는 070507특정 줄의 csv를 PHP로 읽어들입니다.

이 방법을 사용하여이 큰 파일을이 문서에서 읽는 것은 너무 많은 시간이 걸릴 것이다.

if (($handle = fopen("test.csv", "r")) !== FALSE) { 
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { 
} 
fclose($handle) 
} 

간단한 해결책이 필요합니다. 그리고 이것이 가장 간단한 방법이라면 특정 행을 읽는 방법을 알려주시겠습니까?

+0

에 구문 분석 할 수 있습니다) 배열을 사용하여 파일 (로 파일을 얻을 수 있습니다 : . – prava

+0

그러면 특정 행을 읽는 방법은 무엇입니까? –

답변

1

당신은, 당신이 당신이 내가 추측 사용하는 편리한 하나 인 특정 라인을 대상으로하고 CSV

$lines = file('test.csv'); 
$row = $lines[70507]; // Assuming one header row 
$csvdata = str_getcsv($row); // Parse line to CSV 

$num = count($data); // Get number of columns 
for ($c=0; $c < $num; $c++) { // Loop through columns 
     echo $data[$c] . "<br />\n"; // Echo column 
} 
1

이것은 특정 행을 읽는 방법입니다.

$ch = fopen($link_to_file); 
$found = ''; 

/* If your csv file's first row contains Column Description you can use this to remove the first row in the while */ 
$header_row = fgetcsv($read_file); 

/* This will loop through all the rows until it reaches the end */ 
while(($row = fgetcsv($ch)) !== FALSE) { 

    /* $row is an array of columns from that row starting at 0 */ 
    $first_column = $row[0]; 

    /* Here you can do your search */ 
    /* If found $found = $row[1]; */ 
    /* Now $found will contain the 2nd column value (if found) */ 

} 
관련 문제