esandra Posted October 2, 2010 Share Posted October 2, 2010 This is the code that i'm using which works fine except that i have to make lots of changes in my xls file before i `save as` into a csv and any little mistake could cause the program not to work foreach(explode($lineseparator,$csvcontent) as $line) { $lines++; $line = trim($line," \t"); $line = str_replace("\r","",$line); /************************************ This line escapes the special character. remove it if entries are already escaped in the csv file ************************************/ $line = str_replace("'","\'",$line); /*************************************/ $linearray = explode($fieldseparator,$line); $linemysql = implode("','",$linearray); if($addauto) $query = "insert into $databasetable values('','$linemysql');"; else $query = "insert into $databasetable values('$linemysql');"; $queries .= $query . "\n"; @mysql_query($query); } @mysql_close($con); this is how my actual csv looks like. I want this script to completely disregard any other things that sould not be dumoed into my database but i am clueless on how to do that ,,,,,,,,, COLLECTION ON ARRASTRE/WHARFAGE,,,,,,,,, ,,,,,,,,, "ENTRY DATE: AUGUST 20, 2010",,,2010 MP-AW NO:,,187,,,, TOTAL COLLECTIONS: P ,,"20,610.32",,,,,,, ,,,,,,,,, OR #:,313522 - 313550,,ARRASTRE,WHARFAGE,TOTAL,,,, 313522,0819MZ2010-94,TRIPLEX ENTERPRISES INC.,115.36,47.73,163.09,2010-08-20,187,, 313523,0819MZ2010-95,VC BERMEJO,120.37,48.33,168.70,2010-08-20,187,, OR #:,313551 - 313572,,,,,2010-08-20,187,, 313551,0821ML2010-37,OCEANIC SALES,95.43,45.36,140.79,2010-08-20,187,, 313552,0819MZ2010-119,HI - TECH STEEL IND. CORP.,465.61,89.43,555.04,2010-08-20,187,, ,,,,,,,,, ,,TOTAL:,P,"20,610.32",,,,, ,,,,,,,,, ,,,,,,,,, PREPARED BY: ____________________ ,,,,,,,,, , JUDY ANNE A. BUDIAO,,,,,,,, ,,,,,,,,, ,,,,,,,,, NOTED BY: __________________,,,,,,,,, , ALBERTO O. LAZA,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,, ,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, ,,,,,,,,, Quote Link to comment Share on other sites More sharing options...
The Letter E Posted December 5, 2010 Share Posted December 5, 2010 Try the fgetcsv() function. http://php.net/fgetcsv I've recently been doing some CSV parsing and had a lot of luck with this. I have been using preg_match to search for relevant data in the array. Good Luck. : ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.