Jump to content

How to random-access files with PHP?


tcjohans

Recommended Posts

I am looking for a way to random-access text files from a PHP-based script. I don't think PHP itself has any functions that can do this. But are there any other solutions, e.g. using Python, Perl, etc. and somehow interact with PHP?? Or some other way??? Any suggestions welcome...

 

By the way, are there any fundamental reasons why PHP should not be able to do this or is it just that no one still has developed the necessary PHP library/extension??

 

Thomas

Link to comment
https://forums.phpfreaks.com/topic/71314-how-to-random-access-files-with-php/
Share on other sites

I found this reply at some forum from 2003 to this very issue:

 

-----

 

In order to uses random access, you should, indeed, use fseek().

 

But then you need to know how how your file looks like,

that is, each record must be of either fixed lenght, or

each record should store a "pointer" about how long they

are.

 

Any file polated with lumps wont do here.

 

Why is this needed? Simply becuase fseek() moves the read

head to a certain position in your file, and if you don't

know what position you like to go to then fseek() is kind

of useless.

 

---------

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.