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

 

---------

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.