Forum Moderators: coopster

Message Too Old, No Replies

file reading in php

starting froma particular location

         

Silent Miracle

7:39 am on Jun 9, 2011 (gmt 0)

10+ Year Member



hey ! i want to read a text file... actually my text file contains 6 digit serial number in the start and then from 7th character onward is my real data. I tried to read file from the 7th character but couldnt do so.. can anyone pleaseeeee help me how can i do this... i tried to do file_get_contents() bt didnt get the required result with that also...

Chlikikijleelgus

8:30 am on Jun 9, 2011 (gmt 0)

10+ Year Member



I would use fgets(file), which gives you the file as a string.

then, I would remove the first 6 characters from said string.

Silent Miracle

9:50 am on Jun 9, 2011 (gmt 0)

10+ Year Member



actually what i want to do is take the first 6 digits and then save them in a column in database and then from 7th digit onwards i would take the next 10 values and save them in database and plot the graph from those 10 values... so m confused.. dnt knw what to do :S

brotherhood of LAN

10:03 am on Jun 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



fseek($fp,6);

The above would change the file pointer to the 7th character (because you start counting at 0).

You would probably want to do something like:

$fp = fopen('file.txt','rb'); $six = fread($fp,6); while(!feof($fp)) { $line = fgets($fp); // Do stuff here }

Silent Miracle

4:54 am on Jun 10, 2011 (gmt 0)

10+ Year Member



thanks brotherhood of LAN ... :) with this code i was able to separate out the serial number from the remaining data in my text file