php - Strip "$" from csv file -
i have php page takes in csv file , uploads database. issue having of fields have '$' not need. there way remove $ of fields?
data structure
coll_id cocc_id agedtotal paymenttotal 5074 11110 $7.50 ($7.50)
my query
$deleterecords = "truncate table mytable"; //empty table of current records mysql_query($deleterecords); //upload file if (isset($_post['submit'])) { $i=0; if (is_uploaded_file($_files['filename']['tmp_name'])) { echo "<h1>" . "file ". $_files['filename']['name'] ." uploaded successfully." . "</h1>"; echo "<h2>displaying contents:</h2>"; readfile($_files['filename']['tmp_name']); } //import uploaded file database $handle = fopen($_files['filename']['tmp_name'], "r"); while (($data = fgetcsv($handle, 1000, ",")) !== false) { if ($i>0){ $import="insert mytable(coll_id, cocc_id, agedtotal, paymenttotal) values('$data[0]','$data[1]','$data[2]','$data[3]')"; mysql_query($import) or die(mysql_error()); } $i++; }
for whole file
$string = preg_replace( '/((:?.*?\,){2}.*?)\$/', '$1', $string );
2 ((number of column contains $ symbol) - 1)
or
$data[2] = str_replace('$', '', $data[2]);
Comments
Post a Comment