Thursday, February 10, 2011

Read Text file Using PHP

Please find the logic:
$file_handle = fopen("file.txt", "rb");
while (!feof($file_handle) ) {

$line_of_text = fgets($file_handle);

$parts = explode(' ', $line_of_text);
foreach ($parts as $keys){
if($keys != ''){
$query_data[] =$keys;
}else{
$query_data[] ="NULL";
}
}

echo $str = implode(',', $query_data);
?>

1 comment: