Jump to content

[SOLVED] Working with large lists


soadlink

Recommended Posts

Hello,

I am working with processing large lists of words (over 10mb for some!), and they have 1 word or string on each line. I WAS using a different method, but it was eating up my memory because it would load the entire list into memory, so I was forced to take a different approach. I'm using command line for this. Here is my attempt:

 

<?php
$file = 'largelist.txt';
$handle = @fopen($file, "r");
if ($handle) 
{
	while (!feof($handle))
		{
			$buffer = fgets($handle);
			echo md5($buffer) . "\n";
		}
fclose($handle);
}
?>

 

So the code should echo the md5 hash for each list item on a new line, but the problem is that the MD5s are not the correct when it does. Only the very last md5 processed in the list is correct. I believe this may have to do with hidden line breaks being inserted.  I would like to be able to decide when line breaks are used. >:(

 

So basically what I am looking for is: to be able to process each word in the list as I wish, but only the word! Not anything else like line breaks or hidden chars; I choose when the line breaks \n come in if I need them! Also, it would be nice to use the same variable each time around in the loop for the current word in the list (i.e. in my example I was able to use $buffer for each list item). This is probably a given though.

 

Thanks, and if I confused anyone let me know, and I'll try to explain it better 8)

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.