Jump to content

reading from file


alin19

Recommended Posts

how do i start reading a file from a specified bit? and find out the bit that i'm curently?

 

a have  a file that looks like this:

 

php           apache           mysql

michele      alina               john

 

i what to start reading like this:

 

x[0][0]="php";

x[0][1]="apache";

x[0][2]="mysql";

now find out what is the curent bit

j=//curent bite;

then start reading from j:

 

x[1][0]="michele"

x[1][1]="alina"

x[1][2]="john"

i=//curent bite

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/101781-reading-from-file/
Share on other sites

You can "seek" to a certain place in a file using fseek.

 

http://www.php.net/fseek

 

You can determine the current byte position using ftell.

 

http://www.php.net/ftell

 

However I think what you want is a combination of more common functions:

 

// Read the entire file into an array, one line to an element
$file = file("/path/to/file");

// loop through the lines
foreach ($file as $line) {
  // split each line on one or more space characters ("\t", " ", etc)
  $data[] = preg_split('/\s+/', $line);
}

echo '<pre>' . print_r($data, true) . '</pre>';

Link to comment
https://forums.phpfreaks.com/topic/101781-reading-from-file/#findComment-520829
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.