johnny042 Posted January 8, 2013 Share Posted January 8, 2013 (edited) So I have a need to generate md5 hashes for multiple lines out of a textarea. The problem is all of the individual "\n" lines are returning incorrect md5 outputs EXCEPT for the last line (it always returns the correct md5 output) Here is the code and a sample input/output test at the bottom: The HTML form <form action="hash.php" method="post"> <textarea name="hashed" rows=20 cols=41></textarea></br> <input type="submit" value="Generate"> </form> PHP code used to take individual \n lines and generate the individual line md5 output $data = $_POST['hashed'] ; foreach(explode("\n", $data) as $line) { $hashedData = hash('md5',$line, FALSE); echo '<strong>'. $hashedData .'</strong></br>'; } 1. You'll notice the first line (apple) generates "md5(apple + something else)" (I'm thinking the actual \n is generated as part of apple hence wrong output) 2. Same thing happens to orange 3. The third line (apple) generates the correct "md5(apple)" output Sample input: apple orange apple Sample output: 2f9c032ecf479087117e8d6f7fe1a84f 5b3ef7abd937c92e99d740df67182c1b 1f3870be274f6c49b3e31a0c6728957f Any suggestions or a possible workaround? A few things already tried: - using commas as a separator but it didn't work out too well - tried reverse-md5'ing the wrong output but no one has yet to rainbow it - Clean $line from enter \n spaces and %20 spaces, no dice $clean = str_replace(' ','',$str); Edited January 8, 2013 by johnny042 Quote Link to comment https://forums.phpfreaks.com/topic/272878-hashing-multiple-lines-from-a-textarea/ Share on other sites More sharing options...
Jessica Posted January 8, 2013 Share Posted January 8, 2013 Did you try trim? Quote Link to comment https://forums.phpfreaks.com/topic/272878-hashing-multiple-lines-from-a-textarea/#findComment-1404333 Share on other sites More sharing options...
requinix Posted January 8, 2013 Share Posted January 8, 2013 echo md5("apple\r"); Quote Link to comment https://forums.phpfreaks.com/topic/272878-hashing-multiple-lines-from-a-textarea/#findComment-1404336 Share on other sites More sharing options...
johnny042 Posted January 8, 2013 Author Share Posted January 8, 2013 echo md5("apple\r"); Did you try trim? BOTH were great replies !! It was Jessica for the win, Thank you Based Jessica :happy-04: Quote Link to comment https://forums.phpfreaks.com/topic/272878-hashing-multiple-lines-from-a-textarea/#findComment-1404340 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.