Current location: Hot Scripts Forums » Programming Languages » PHP » Using data stored in a text file

Using data stored in a text file

Reply
  #1 (permalink)  
Old 04-08-08, 09:19 AM
Philmo's Avatar
Philmo Philmo is offline
New Member
 
Join Date: Apr 2008
Location: UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Using data stored in a text file

Basically what I am trying to build (as an assignment for my degree) is an application which takes data collected from Land Surveying and then overlays that onto Google Earth using PHP and Javascript.

The surveyor uses a piece of equipment to record the location of given points, that data is then stored in a text file with each row being one individual point and the corresponding columns for the X coordinate, Y coordinate and height (separated by tabs), all values are numerical. I need to extract the X and Y coordinates and then convert them to another coordinate system and then display this on Google Maps.

My lecturer has provided me with a typical text file of the data to test the application. I have no problems entering the data into Google Earth, and have been using this site: www.nearby.org.uk to convert the coordinates manually. This site also offers the conversion code for download, so I can use it to batch convert the data.

Here is what I have managed to do so far by manually extracting the data from the text file: http://www.philmorrow.co.uk/lboro/case1/

I have spent a great deal of time learning how to remove the tabs separating the columns and call each column individually but I suck at PHP and can only do this for the first row – figuring out how to automate this is beyond me. I have read loads about arrays of arrays for 2 dimensional things and about using databases but I don’t really understand it.

So where I am at the moment is that I effectively have 3 separate little scripts which I need to somehow combine so that I can (ideally) upload a text file and then see the data plotted on Google Earth in one swift process.

I am not asking for someone to do this for me but I could really do with an explanation of what I need to do. Do I need a MySQL database to handle this kind of thing? Can arrays handle files with up to 5 columns and potentially 10,000 rows?

Any help would be GREATLY appreciated!


PS. Sorry if this is too long-winded or missing crtical info, I've got myself into a bit of a mess trying to figure this out. I'm completely new to PHP and have been learning things as and when I needed them.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-08-08, 09:59 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Phil,
Do you have an example of what a few lines of the file look like? Also I sugest you go with a mysql database for this as php should be able to handle the 10,000 rows but the database will give you greater flexibility in using the data

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-08-08, 02:07 PM
Philmo's Avatar
Philmo Philmo is offline
New Member
 
Join Date: Apr 2008
Location: UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Jay, thanks for the quick reply.

The entire sample data file can be found here:

http://www.philmorrow.co.uk/lboro/ven88f.dat

It looks like I'll be going down the database route then...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-08-08, 02:20 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
OK Phil what you will want to do is the following
PHP Code:
$handle fopen("/path/to/file""r");
if (
$handle) {
    while (!
feof($handle)) {
        
$buffer fgets($handle);
        
//WILL PARSE DATA SEPERATED BY TABS INTO SEPERATE ARRAY ELEMENTS
        
$arr explode("\t",$buffer);
#####################################
#########ADD TO DATABASE HERE########
#####################################
    
}
    
fclose($handle);

You will need to make a query where i have marked to insert the data into your mysql database. Also, you will need to connect to the database before the WHILE statement, and close the connection after the closing curly brace }

Hope that gets you started
Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with my largest perl script. Grabbing data from a file. Sunnmann Perl 2 04-23-08 04:27 AM
Submit button data written to a .txt file ziul Everything Java 0 08-08-07 04:41 PM
Stripping a text file and ceating some variables creepycridler PHP 3 06-07-06 11:15 PM
Need Your HelP! Loading Multiple External Text into Multiple Dynamic Text Fields Flash_Boi Flash & ActionScript 2 03-30-06 04:27 PM
PHP write to text file veeco Script Requests 1 03-02-04 02:14 PM


All times are GMT -5. The time now is 06:53 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.