The first method:
Ideas: It is not so easy to import data from Excel tables into a database directly, you can save the Excel table as a. csv-formatted document (features: content is separated by commas), and then processed into a two-dimensional array through a series of document manipulation functions, and then further processed to import the database
The idea is correct but sometimes the problem (explode here, because the data may also contain the "," number, so generally do not use this method, see the second method)
1: Prepare an Excel table to import the data:
2: Document saved as. csv suffix (feature: content separated by commas)
3: Handling of document manipulation functions
1 $filepath=Str_replace("\\", "/",dirname(__file__).‘ /score.csv '); 2 $TP=fopen($filepath, ' RB ');3 while(!feof($TP)){4 $con=fgets($TP);5 if($con!=NULL){6 $row[]=Explode(",",$con);//mark with "," as a split7 }8 }9 Ten One fclose($TP); A Echo"<table border=1>"; - for($i= 0;$i<Count($row);$i++){ - Echo"<tr><td>{$row[$i][0]}</td><td>{$row[$i][1]}</td></tr> "; the } - Echo"</table>";
Operation Result:
The second method:
PHP comes with a function to process the CSV file, you can get the contents directly, and return an array;
1 $filepath=Str_replace("\\", "/",dirname(__file__).‘ /score.csv ');2 $TP=fopen($filepath, ' RB ');3 while(!feof($TP)){4 $con=Fgetcsv($TP);//PHP comes with a function to get the contents of a CSV document;5 Echo"<pre>";6 Print_r($con);7 Echo"</pre>";8 }9 fclose($TP);
Operation Result:
Delete operation of extended file: Unlink ()
<?PHPHeader("Content-type:text/html;charset=utf-8");$filename=Str_replace("\\", "/",dirname(__file__)." /ceshi/");$arr=Array("A.txt", "B.txt", "C.txt", "D.txt");foreach($arr as $v){ if(filesize($filename.$v) <10){ unlink($filename.$v); Echo"The number of bytes is less than 10."$filename.$v." The file was deleted <br/> "; Continue; }Else{ $con=file_get_contents($filename.$v); if(Stripos($con, "fuck")!==false){ unlink($filename.$v); Echo"Containing uncivilized words."$filename.$v." The file was deleted <br/> "; } }}?>
How do I import data from an Excel table into a database?