iceblox Posted September 26, 2009 Share Posted September 26, 2009 Hi Guys, I have a script which opens a file using file() then it reads this information from an array. Is there another way i can achieve this without using file()? Thanks in advance, Phil Quote Link to comment https://forums.phpfreaks.com/topic/175611-another-way-to-read-a-file-into-an-array/ Share on other sites More sharing options...
monkeytooth Posted September 26, 2009 Share Posted September 26, 2009 depends on the file type your opening and reading from.. then depends from there what your doing with what type of file. Quote Link to comment https://forums.phpfreaks.com/topic/175611-another-way-to-read-a-file-into-an-array/#findComment-925356 Share on other sites More sharing options...
khr2003 Posted September 26, 2009 Share Posted September 26, 2009 have tried other functions like: fileread, get_file_contents or curl? Quote Link to comment https://forums.phpfreaks.com/topic/175611-another-way-to-read-a-file-into-an-array/#findComment-925357 Share on other sites More sharing options...
.josh Posted September 26, 2009 Share Posted September 26, 2009 my guess is if file() isn't an option for you, chances are the other functions available aren't going to be either. Unless you are wanting to read/process the file a different way than how file() does it? Quote Link to comment https://forums.phpfreaks.com/topic/175611-another-way-to-read-a-file-into-an-array/#findComment-925367 Share on other sites More sharing options...
iceblox Posted September 26, 2009 Author Share Posted September 26, 2009 Its quite a lengthy script which works however when the file is large the server runs out of memory and its running on max memory! I had some code which basically reads and replaces 12500 lines then starts at 12501 til 25000. If this makes sense? I believe file opens the whole file and i think thats what the problem is.. So what i was hoping to find was a func that would alllow this to work without re writing the whole script? Thanks again Phil Quote Link to comment https://forums.phpfreaks.com/topic/175611-another-way-to-read-a-file-into-an-array/#findComment-925371 Share on other sites More sharing options...
.josh Posted September 26, 2009 Share Posted September 26, 2009 you can use fopen and fread to read it one line at a time. Quote Link to comment https://forums.phpfreaks.com/topic/175611-another-way-to-read-a-file-into-an-array/#findComment-925378 Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2009 Share Posted September 26, 2009 reads and replaces 12500 lines ... If this makes sense? No, that does not make 'computer' sense. After you have a few thousand lines of data, you should migrate it to a database and let the database engine do the work for you. Quote Link to comment https://forums.phpfreaks.com/topic/175611-another-way-to-read-a-file-into-an-array/#findComment-925381 Share on other sites More sharing options...
Daniel0 Posted September 26, 2009 Share Posted September 26, 2009 reads and replaces 12500 lines ... If this makes sense? No, that does not make 'computer' sense. After you have a few thousand lines of data, you should migrate it to a database and let the database engine do the work for you. That might not be applicable. What if he is writing a script to analyze Apache access logs for instance? What if he is writing the script that is migrating to a DBMS? Check this out: [daniel@phpfreaks logs]$ wc -l access.log.2009-09-25 681486 access.log.2009-09-25 Quote Link to comment https://forums.phpfreaks.com/topic/175611-another-way-to-read-a-file-into-an-array/#findComment-925386 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.