Can PHP script read a text file
Can someone show me?
I need to import a text file into a sql database
Thanks
Charlie Crimmel
Can PHP script read a text file
Moderator: General Moderators
Re: Can PHP script read a text file
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Re: Can PHP script read a text file
Thanks:
This is my first attempt to use MySQL and PHP
If I had a Vendor text file with the following fields
Vendor_ID , Vendor_Number , Vendor_name, Address1, Address2, City, State, Zip
the data might look like
0001,"V12345","Joe Smith","123 Any place Street","Apt. 123","Any City","WV","11111"
0002,"V23456","John Smith","234 Any place Street","Apt. 123","Any City","OH","2222"
0003,"V34567","Bob Smith","345 Any place Street","Apt. 123","Any City","KY","33333"
0004,"V45678","Mary Smith","456 Any place Street","Apt. 123","Any City","IN","44444"
0005,"V56778","Sue Smith","567 Any place Street","Apt. 123","Any City","TN","55555"
What would be the syntax to read this text file and import it into the Vendor SQL Table with the same fields.
Thanks
Charlie Crimmel
This is my first attempt to use MySQL and PHP
If I had a Vendor text file with the following fields
Vendor_ID , Vendor_Number , Vendor_name, Address1, Address2, City, State, Zip
the data might look like
0001,"V12345","Joe Smith","123 Any place Street","Apt. 123","Any City","WV","11111"
0002,"V23456","John Smith","234 Any place Street","Apt. 123","Any City","OH","2222"
0003,"V34567","Bob Smith","345 Any place Street","Apt. 123","Any City","KY","33333"
0004,"V45678","Mary Smith","456 Any place Street","Apt. 123","Any City","IN","44444"
0005,"V56778","Sue Smith","567 Any place Street","Apt. 123","Any City","TN","55555"
What would be the syntax to read this text file and import it into the Vendor SQL Table with the same fields.
Thanks
Charlie Crimmel
Re: Can PHP script read a text file
Use preg_match_all to extract the individual values, then insert them into your database.crimmelcp wrote:Thanks:
This is my first attempt to use MySQL and PHP
If I had a Vendor text file with the following fields
Vendor_ID , Vendor_Number , Vendor_name, Address1, Address2, City, State, Zip
the data might look like
0001,"V12345","Joe Smith","123 Any place Street","Apt. 123","Any City","WV","11111"
0002,"V23456","John Smith","234 Any place Street","Apt. 123","Any City","OH","2222"
0003,"V34567","Bob Smith","345 Any place Street","Apt. 123","Any City","KY","33333"
0004,"V45678","Mary Smith","456 Any place Street","Apt. 123","Any City","IN","44444"
0005,"V56778","Sue Smith","567 Any place Street","Apt. 123","Any City","TN","55555"
What would be the syntax to read this text file and import it into the Vendor SQL Table with the same fields.
Thanks
Charlie Crimmel
Re: Can PHP script read a text file
Thanks:
If I were doing this in another programming language I would DIM variables
DIM vVendor_ID as N
Dim vVendor_Number as C
Dim vVendor_name as C
Dim vAddress1 as C
Dim vAddress2 as C
Dim vCity as C
Dim vState as C
Dim vZip as C
Then initializee the variables
vVendor_ID = 0
vVendor_Number =""
vVendor_Name=""
vAddress1=""
vAddress2=""
vVendor_City=""
vVendor_State=""
vVendor_Zip=""
Then open the file
read the first record
populate the variables
write the record to the Table
read the next record
loop until the EOF
Is this the same concept as preg_match_all
or does PHP have a way to do it like described above.
Thanks
Charlie Crimmel
If I were doing this in another programming language I would DIM variables
DIM vVendor_ID as N
Dim vVendor_Number as C
Dim vVendor_name as C
Dim vAddress1 as C
Dim vAddress2 as C
Dim vCity as C
Dim vState as C
Dim vZip as C
Then initializee the variables
vVendor_ID = 0
vVendor_Number =""
vVendor_Name=""
vAddress1=""
vAddress2=""
vVendor_City=""
vVendor_State=""
vVendor_Zip=""
Then open the file
read the first record
populate the variables
write the record to the Table
read the next record
loop until the EOF
Is this the same concept as preg_match_all
or does PHP have a way to do it like described above.
Thanks
Charlie Crimmel
Re: Can PHP script read a text file
You would be much better off using fgetcsv() as it can detect individual values using your comma delimeters.
There's some good examples on the linked page.
There's some good examples on the linked page.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Re: Can PHP script read a text file
But I wrote a regex : (. /(?:"?(.*?)"?)(?:,|\n|\r|$)+/scottayy wrote:You would be much better off using fgetcsv() as it can detect individual values using your comma delimeters.
There's some good examples on the linked page.