Reading a text file using byte offsets

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
terji
Forum Commoner
Posts: 37
Joined: Tue May 14, 2002 5:27 pm
Location: Denmark

Reading a text file using byte offsets

Post by terji »

I've got this text file that I'm supposed to read.
The elements in the file are separated only by bytes. For example one element may reside at starting point 146 bytes and end at point 211 bytes.
I have all the byte references in an array so all that I'm missing is a function to do the actual reading.
The array contains all the byte references from 0 to eof and I want to read the entire file.
Can anyone give me some tips or example code on how to do this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

we're not going to do your homework for you.. but here's a hint:

Code: Select all

<?php

for($x = 0, $y = strlen($file_contents); $x < $y; $x++)
{
  $current_byte = $file_contents{$x};
}

?>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

[php_man]fseek[/php_man] ?
terji
Forum Commoner
Posts: 37
Joined: Tue May 14, 2002 5:27 pm
Location: Denmark

Thx

Post by terji »

Those two tips got my brain spinning again....
Thx
Post Reply