[PHP, MySQL] to export the data into the database

Abstract: [PHP, MySQL] to export the data into the database


A few days ago, in doing export database (MySQL to xls) design, it will encounter a very serious problem.

It is to export data to Excel files when, if the contents of the field in the database has text and the type of data stored, then there is a line break, line break will occur when exporting in Excel.

That is, it will break to the next column, in order to solve this problem, carefully studied it done some things when I do file input ...


$chapterRange= addslashes($_POST['chapterRange']);
$testRange = addslashes($_POST['testRange']);
$numberofPeople = addslashes($_POST['numberofPeople']);
$environment = addslashes($_POST['environment']);
$homeBook = addslashes($_POST['homeBook']);

Found in the data entered into the database before I made addslashes, but think about it ... This has to do with input? He just added a backslash before the special character of it, so I put the question to the direction of export.

Because it is clear that a line break will either need n is in trouble, is either need
to do strange, so I have to do a deal with the direction of n.

I then added as a function of n-substituted at the output:


$chapterRange = str_replace("n","",$row[chapterRange]);
$testRange = str_replace("n","",$row[testRange]);
$numberofPeople = str_replace("n","",$row[numberofPeople]);
$environment = str_replace("n","",$row[environment]);
$homeBook = str_replace("n","",$row[homeBook]);

Then the output ... bad, export Excel files off-line is still the same, how do ..

I thought, adding a function to do inside look at:


$chapterRange = mysql_real_escape_string($chapterRange);
$testRange = mysql_real_escape_string($testRange);
$numberofPeople = mysql_real_escape_string($numberofPeople);
$environment = mysql_real_escape_string($environment);
$homeBook = mysql_real_escape_string($homeBook);

mysql_real_escape_string This function is mainly in the SQL special characters do show that after joining, very nice ... although there are a bunch of output r of line breaks in the exported file in Excel, but later tests did import, it is OK!

Reference to see Hello ~


Original: Large column  [PHP, MySQL] to export the data into the database


Guess you like

Origin www.cnblogs.com/petewell/p/11516556.html