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
Share on other sites

<?php

$file=fopen("C:\Documents and Settings\user\Desktop\php\\tickers.txt",'r');

if ($file)

while (!feof($file))

{

 

$order=fgets($file,999);

echo $order;

}

 

?>

 

how do i open that file or start reading it from a specified place?

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.