|  | Posted by Moot on 11/15/06 16:08 
Advo wrote:> Hi there.
 >
 > I've got some data currently stored in an Excel table, or a notepad
 > file depending on which would be easier to work with.. Im assuming
 > notepad(.txt) so that data can be read into php.
 >
 > Anyway, this data is majorly corrupted and contains stuff i dont need.
 > For instance, a sample line is:
 >
 > MNs73dd78INFORMATION I NEED 32427  12759 39384425  495242   15.206412
 >  0.191214 44.164503 -93.993798
 >
 > As you can see, its pretty messed up. I only need the "INFORMATION I
 > NEED" part, not the 9 characters before, nor any numbers or decimal
 > places afterwards.
 >
 > I cant do this manually, as there are tens of thounsands of records.
 >
 > Any ideas how I could go about this please.
 >
 > Im assuming I would some how remove the first 9 characters, and then
 > some how remove all numbers and decimal places, but i've got no idea
 > how to go about it.
 >
 > Kind Regards
 
 Open the file
 Loop through each line with fgets [1]
 Use substr [2] to yank out from character 9 to whatever you need
 Dump data into an array or an output file as you see fit
 
 Now, if the data in each line you need is variable length (you don't
 say), then it becomes trickier.  You may have to tokenize the line with
 something like explode [3], then do some logic to get only the tokens
 you want.  Or you may be able to figure out a regular expression to
 trim off the data to the right (I'll leave that to someone much wiser
 than I).  There has to be some kind of standard format to the file
 which delimits each field (either that, or whoever set up this file
 royally screwed up).
 
 [1] - http://us3.php.net/manual/en/function.fgets.php
 [2] - http://us3.php.net/manual/en/function.substr.php
 [3] - http://us3.php.net/manual/en/function.explode.php
  Navigation: [Reply to this message] |