Page 1 of 1
MD5'ing a bunch at once
Posted: Wed Oct 26, 2005 6:24 pm
by HiddenS3crets
What I am trying to do is input a list of words, then have PHP code create a MD5 equivalent of each, then reformat the line to look like:
MD5:real_word
To go about this I would need to read the input one line at a time, create a MD5 equivalent, modify the line, then go on to the next line.
sample input:
cat
dog
people
How can I go from cat to dog, then dog to people?
Posted: Wed Oct 26, 2005 6:31 pm
by feyd
a loop.

Posted: Wed Oct 26, 2005 6:33 pm
by HiddenS3crets
Lol, but how specifically? Is there a function to move from one line to another or something?
Posted: Wed Oct 26, 2005 6:39 pm
by feyd
not specifically. How are you getting these lines? From a file? From a form?
Files would use
file() or siblings functions while forms would use
explode() to break apart the data into individual elements of an array. A basic foreach loop can be used from there.
Posted: Wed Oct 26, 2005 6:41 pm
by HiddenS3crets
It comes from a form. I'll check out explode(), thanks
Posted: Wed Oct 26, 2005 7:09 pm
by HiddenS3crets
I ended up solving this a different way... this is my code
Code: Select all
<?php
$str = $_POST['str'];
$length = str_word_count($str);
if(isset($str)) {
for($x = 0; $x < $length; $x++) {
$ind = explode("\n", $str);
$md5 = md5($ind[$x]);
echo $md5 . ":" . $ind[$x] . "<br>";
}
}
?>
Posted: Wed Oct 26, 2005 7:11 pm
by feyd
exploding the string repeatedly would just wasted processing time.. store the results of the explosion.. and use count() on the exploded data..
Posted: Thu Oct 27, 2005 12:58 am
by Jenk
What feyd is suggesting, is something like:
Code: Select all
<?php
$str = explode("\n", $_POST['str']);
$md5str = array();
foreach ($str as $val) {
$md5 = md5($val);
$md5str[] = $md5;
echo "$md5:$val<br />\n";
}
?>
So now you have the original text in the array $str, and the md5 hashed text in the array $md5str.