473,574 Members | 3,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP read large file line by line?

hi,

how to read a large php file line by line?

fread can't?

thanks.

Oct 13 '06 #1
5 72597
Hmm howa <ho******@gmail .comwrote:
hi,

how to read a large php file line by line?

fgets

--
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

2be || !2be $this =mysql_query();
Oct 13 '06 #2

$file_array = file($file_name );

foreach ($file_array as $line_number =$line)
{
// Handle the line
}

See: http://us3.php.net/manual/en/function.file.php
howa wrote:
hi,

how to read a large php file line by line?

fread can't?

thanks.
Oct 13 '06 #3
ZabMilenko wrote:
>
$file_array = file($file_name );

foreach ($file_array as $line_number =$line)
{
// Handle the line
}

See: http://us3.php.net/manual/en/function.file.php
howa wrote:
>hi,

how to read a large php file line by line?

fread can't?

thanks.
The problem with your solution is it reads the entire file into the
array. Note he said LARGE FILE. This could very quickly run him out of
memory.

Ikciu has the correct answer. fgets() is the way to go.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Oct 13 '06 #4
[ Please don't top-post. Read http://www.caliburn.nl/topposting.html ]

ZabMilenko top-posted (corrected):
howa wrote:
>hi,

how to read a large php file line by line?

fread can't?

thanks.

$file_array = file($file_name );

foreach ($file_array as $line_number =$line)
{
// Handle the line
}

See: http://us3.php.net/manual/en/function.file.php
What if the file is larger than memory_limit (8Mb)?

http://www.php.net/manual/en/ini.cor...i.memory-limit

fgets() is the right answer in this case.

So, instead of coding with file() which works now with a 200K file,
start with fgets and your script will not break when the file grows.

http://www.php.net/fgets

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Oct 13 '06 #5
I would go fgets, this will allow you to control how much of the file
you would like to do, or maybe possibly do it in batches.

On Oct 14, 4:17 am, Pedro Graca <hex...@dodgeit .comwrote:
[ Please don't top-post. Readhttp://www.caliburn.nl/topposting.html]

ZabMilenko top-posted (corrected):
howa wrote:
hi,
how to read a large php file line by line?
fread can't?
thanks.
$file_array = file($file_name );
foreach ($file_array as $line_number =$line)
{
// Handle the line
}
See: http://us3.php.net/manual/en/function.file.phpWhat if the file is larger than memory_limit (8Mb)?

http://www.php.net/manual/en/ini.cor...i.memory-limit

fgets() is the right answer in this case.

So, instead of coding with file() which works now with a 200K file,
start with fgets and your script will not break when the file grows.

http://www.php.net/fgets

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Oct 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
17062
by: Chris | last post by:
Can anybody help. I need to read a txt file backwords line by line. Can anybody help me do this. Thanks Chris
2
12972
by: ohaya | last post by:
Hi, I'm a real newbie, but have been asked to try to fix a problem in one of our JSP pages that is suppose to read in a text file and display it. From my testing thus far, it appears this page is somehow hanging when relatively large file is used. My original intent was to try to just add a check for file size, and error out somehow if...
6
6556
by: guillaume | last post by:
I have to read and process a large ASCII file containing a mesh : a list of points and triangles. The file is 100 MBytes. I first tried to do it in memory but I think I am running out of memory therefore I decide to use the shelve module to store my points and elements on disks. Despite the fact it is slow ... Any hint ? I think I have the...
1
2066
by: Yong Wang | last post by:
Hi, All: I need to read a input file as soucre to process data. Ideally if I can read a line from input file as a list (coloumn separate by white space), reorganize field in a line. Does python has this kind of command ? for example, I read a line has: "IP MAC Date..." as a line from input file, How can I only get MAC ? Thanks, Yong
12
5676
by: Martin Dieringer | last post by:
I am trying to split a file by a fixed string. The file is too large to just read it into a string and split this. I could probably use a lexer but there maybe anything more simple? thanks m.
6
3541
by: Kinbote | last post by:
Hi, I'm trying to make a function that opens a file, reads it in line by line, puts each line into an malloc'd array, and returns the array. I suspect I'm going about it in an atypical fashion, as I'm avoiding the use of fscanf and fgets to read in lines. I don't want to have to specify a temporary char* buffer to read in each line, and then...
2
1361
by: Sean Davis | last post by:
This should be a relatively simple problem, but I haven't quite got the idea of how to go about it. I have a VERY large file that I would like to load a line at a time, do some manipulations on it, and then make it available to as a file-like object for use as input to a database module (psycopg2) that wants a file-like object (with read and...
2
5443
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it is several GB in size. When it comes time to read the 5+GB file from inside the zip file, it fails with the following error: File "...\zipfile.py",...
1
1427
by: vaskarbasak | last post by:
Hi All, I have a text file.The file size is very big.I have to read the file from different line number. e.g File test.txt contains 10000000 lines and more.The 1st thread read the file from line 1 to 1000.2 nd thread read the file from line 1100 to 2000.3 rd thread read the file from line 2100 to 3000.. so on. Please help me. Thanks!
0
7758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8270
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7856
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8137
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5335
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3773
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.