I am using following code for importing data into database using txt file
while (!feof($handle)) // Loop til end of file.
{
$buffer = fgets($handle, 4096); // Read a line.
$data_array =explode("|",$buffer);//Separate string by the means of |
$escaped_array = array_map('mysql_escape_string',$data_array);
$escaped_array = '("'.implode('","',$escaped_array).'") ';
if($i !=1) {
echo $sql = 'INSERT INTO '.$tablename.' VALUES'.$escaped_array;
mysql_query($sql) ; //or die(mysql_error().$tablename);// use mysql insert query here
//exit;
}
$i++;
} //end while
it inserting values like INSERT INTO PROVIDER_DEMOGRAPHIC VALUES("10000104","Sand","David","C","MD","Family Practice","","N","N","N","P","125\r\r\n") INSERT INTO PROVIDER_DEMOGRAPHIC VALUES("10000105","Stucky","Mitchell","B","MD","Family Practice","","N","N","N","P","101\r\r\n")
I donot want extra character in last fiels like \r\n\r Please tell me how i can trim it.
fgetcsvand set delimiter to|instead of the default,