Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Creating a PHP script that parses a .txt file and inserts into a mySQL DB
Old 08-16-2007, 11:58 PM Creating a PHP script that parses a .txt file and inserts into a mySQL DB
Junior Talker

Posts: 3
Name: Chester
Trades: 0
Sorry for that mouthful of a subject, but that's what I need to do! I'm not quite a PHP programmer, as this is my first real go at it, but I do know Java and JSP. In fact, I wrote Java code that does exactly what I need. Problems are, you can't execute a Java class via a browser and my web host won't take my WAR file, so I can't execute my own JSPs on my site. I figure PHP can do it, but I don't know where to start.

A little about the text file: it is not a CSV file, nor is it delimited by anything other than two spaces. If there is a negative value, it is cut to one space. (Here is a good breakdown of one of the files: http://ehm.fhockey.com/playersehm%20101.htm) And this is only on certain lines. I have five of them (for now) that I need to parse and insert into my SQL database on my server. For the most part, I understand how to acquire that data via PHP, but I'm not quite sure on the parsing and inserting part.

Can anyone help me out? I've attached my Java code and an example of one of the files I need parsed. (n.b. I was connecting a local Derby server via Netbeans... I'm now looking to go through a mySQL server)

Thanks!
Chester
Attached Files
File Type: zip Archive.zip (3.7 KB, 1 views)
NHLretroproject is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-17-2007, 12:59 AM Re: Creating a PHP script that parses a .txt file and inserts into a mySQL DB
goheadtry's Avatar
Webmaster Talker

Posts: 730
Name: John
Location: United States of America, California
Trades: 0
http://www.webdevelopersnotes.com/tu...ql_tables.php3

look at that maybe that will get you started
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 08-17-2007, 01:24 AM Re: Creating a PHP script that parses a .txt file and inserts into a mySQL DB
Junior Talker

Posts: 3
Name: Chester
Trades: 0
Quote:
Originally Posted by goheadtry View Post
http://www.webdevelopersnotes.com/tu...ql_tables.php3

look at that maybe that will get you started
I've got the SQL part down. That Java code I posted can insert my data into my SQL database after parsing. I just need to know how I can set up something in PHP to correctly parse my text files so I can insert them into my SQL database.
NHLretroproject is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 02:19 AM Re: Creating a PHP script that parses a .txt file and inserts into a mySQL DB
Experienced Talker

Posts: 32
Trades: 0
Take a look at this:

http://hr.php.net/manual/en/function.file.php

and then this

http://hr.php.net/manual/en/function.explode.php

Hope this helped you, if so... talkupatin++

Cheers!
lotar_vk is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 01:39 PM Re: Creating a PHP script that parses a .txt file and inserts into a mySQL DB
Junior Talker

Posts: 3
Name: Chester
Trades: 0
Those will do the trick. Turns out iterating through my file isn't as bad as I thought without knowing the language. It's similar to Java, with just some new structures on how to write code. I just tested part of my new PHP script, and it successfully did what I told it to: parse the file, insert into SQL database, enjoy. Thanks guys!
NHLretroproject is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Creating a PHP script that parses a .txt file and inserts into a mySQL DB
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.11807 seconds with 13 queries