Jump to content

Search flat file


John101

Recommended Posts

OK, here is my problem. I would like to a form that ultimately searches a flat file where the results will give only the data requested in the form.

 

From what I've read you can not do a PHP search of a flat file so my thought process on this was pull the flat file into an array then do a search on the array.

 

Here is an example of my flat file

file.txt

12345|Product 1|Used for something

24680|Product 2|Also used for things

13579|Product 3|Again, can be used for something

and so on...

 

The assumption is that the user will know either the Product name or the number at the beginning and will be able to enter that into a html form, hit go, and receive the results of the row.

 

Any ideas how to accomplish this, I've been searching all over Google for the answer but found nothing. The other trick is there is no MySQL access or any DB for that matter.

 

Thanks for you help in advance

Link to comment
https://forums.phpfreaks.com/topic/162641-search-flat-file/
Share on other sites

$lineSplit = explode(line, "|");

 

so

$lineSplit[0] = 12345

$lineSplit[1] = "Product 1"

 

etc..

 

but u have to get line by line .. which is well.. takes some research

 

they dont have a php function for fopen that does  readNextLine or something thats why i never use flatfiles only mysql.. whats the point of opening a huge flatfile just to get some line in the middle.

 

sure the IO has seek function and some get_file_contents function but i see no way to use them correctly..

Link to comment
https://forums.phpfreaks.com/topic/162641-search-flat-file/#findComment-858371
Share on other sites

Long story short, the problem comes from the Oracle DBAs, they will not give me access (any at all) to their DB, but will output a file once a week with the data needed. Rather than make the user search through a large list, which is what they do now, this will give them the option to type in the 'code' and get the results they are looking for. Speed is not an issue here since it will be used in house.  And really, I don't see why they can just hit 'Ctrl F' and get the answer they need. But that's beyond the point.

 

As for the:

$lineSplit[0] = 12345

$lineSplit[1] = "Product 1"

etc.

 

is there any way to search on these results?

Link to comment
https://forums.phpfreaks.com/topic/162641-search-flat-file/#findComment-858389
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.