Today is mainly to write a PHP import CSV file method, in fact, a lot of online search. Can be implemented how to import. But I encountered two problems when importing, one is to write code on the windows when the test has garbled problem, and then resolved. The second is when it was submitted to the Linux system and it was garbled. I still don't know the reason is garbled, at first I thought it was the cod
Php uses the specified encoding to export mysql Data to a csv file
This example describes how php exports mysql Data to a csv file using the specified encoding. Share it with you for your reference. The specific implementation method is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
content of the stored procedure is as follows:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Create procedure [DBO]. [my_import_csvfile]@ Sourcefilepath nvarchar (
200
),
--
The folder
Where
You upload the CSV file on your server. eg:
'
D: \ dataexchange \ csvtmp
'
@ Sourcefilename nvarchar (
100
),
--
The
Today is mainly to write a PHP import CSV file method, in fact, a lot of online search. Can be implemented how to import. But I encountered two problems when I import, one is to write code on Windows when the test has garbled problems, and then resolved. The second is to submit to the Linux system when there is garbled. I don't know why it's garbled at first, at first I thought it was the code SVN commit er
Introduction to the CSV file:
CSV is a common, relatively simple file format that is widely used by users, businesses, and science. The most widespread application is the transfer of tabular data between programs, which themselves operate in incompatible formats (often in private and/or non-canonical formats). Because
This article introduces the content is about PHP generated CSV file, has a certain reference value, now share to everyone, the need for friends can refer to
Needless to say, the dry stuff.
Method One:
/** * Export Excel (CSV) * @data Export Data * @headlist first row, column name * @fileName output Excel file name */f
of the scientific notation to store, which caused the CRC in the file error.
So, if you want to see real CSV data, it's best to use proprietary software to view it, or convert it into an Excel-specific format and then use Excel to open it.
And as for practical what software open CSV
the text content of the first line of the sample text extracted above. Do not select the carriage return line character here.
Step 9: Use separators to split fields.
Step 10: Here, child is the fields separated by commas in the first line, which must be separated by commas (,) according to the CSV standard.
For non-
occupies three bytes of the UTF-8-encoded file. If you use notepad to save a text file as a UTF-8 encoding method, open the file with UE, switch to the hexadecimal editing status, you can see the beginning of FFFE. This is a good way to identify the UTF-8 encoding file, the
A. csv file Comma-separated values (comma-separated values,csv, sometimes referred to as character-delimited values, because delimited characters can also be not commas), whose files store tabular data (numbers and text) in plain text. Plain
_values,0,-1); Remove the last comma
Fclose ($handle); Close pointer
$query = mysql_query ("INSERT into student (name,sex,age) values $data _values"); Bulk INSERT in Datasheet
if ($query)
{
echo ' Import successful! ';
}else{
echo ' Import failed! ';
}
}
Note that PHP's fgetcsv function makes it easy to work with CSV, which allows you to read a line from the file pointer and parse the
The following is a detailed analysis of the csv file reading, writing, and output downloading operations in php. if you need a friend, refer
The code is as follows:
$ File = fopen('text.csv ', 'r ');
While ($ data = fgetcsv ($ file) {// read the contents of a row in the CSV
.
?
Bytesencoding Form
XX-FE FF
UTF-32, Big-endian
FF FE 00 00
UTF-32, Little-endian
FE FF
UTF-16, Big-endian
FF FE
UTF-16, Little-endian
EF BB BF
UTF-8
?The BOM is not used in Unix-like systems because it destroys the syntax conventions of existing ASCII files.Implementation code IF
Note: When writing a CSV fil
.
?
Bytesencoding Form
XX-FE FF
UTF-32, Big-endian
FF FE 00 00
UTF-32, Little-endian
FE FF
UTF-16, Big-endian
FF FE
UTF-16, Little-endian
EF BB BF
UTF-8
?The BOM is not used in Unix-like systems because it destroys the syntax conventions of existing ASCII files.Implementation code IF
Note: When writing a CSV fil
CSV
(Comma separated value file format)
Comma-separated values (comma-separated values,csv, sometimes referred to as character-delimited values, because delimited characters can also be not commas), whose files store tabular data (numbers and text) in plain text
Read the file:The traditional method of reading. All read out, processed by line:Fp=open ("./ps.txt", "R");Alllines=fp.readlines ();Fp.close ();For Eachline in Alllines:Print EachlineThe recommended read method, using a file iterator, is to read and display only one row at a time. This should be the case when reading large files:Fp=open ("./ps.txt", "R");For Eachline in FP:Print EachlineTo read and write files using pandas:Import Pandas as PDImport Nu
This is because many different databases, such as Oracle, access, MSSQL, MySQL, and DB2, are involved in the work.
Therefore, I have always wanted to create a common data query tool that supports all databases. The operation interface is a uniform interface of MSSQL 2005, so that many client tools can be installed less, you do not need to switch between different database client tools.
Put an initial one. Like the MSSQL operation interface, the table and column information display area is on
odbc| data
CSV files, commonly known as "comma-delimited files", the way to read the CSV file can be read by using iostream ...
I thought this one method, hehe. Until one day. See the connection of the text on the www.ConnectionStrings.com
String:
Text
Odbc
Stand
\ n.
You can use the above method to find that columns can be separated, but not wrapped. You don't seem to know \ nthe.
The solution is to use encodeuricomponent to encode/
CSV export with Chinese problems
All of the above are utf-8 coding, theoretically exporting Chinese should not be a problem.
However, if you export CSV format, using Excel to open it will find that Chinese is garbled, but it is n
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.