r3dn4x Posted July 5, 2007 Share Posted July 5, 2007 I have a list of keyphrases I need to md5() and add to a database. I want to input the keyphrases in a textarea, 1 per line. I've set it up to create an array, $keyword[]... but while running the loop, the md5 is incorrect for all but the first one. What is my problem here? <form action="<?=$PHP_SELF; ?>" method="post"> <textarea name="input" cols="50" rows="20"></textarea> <br> <br> <input name="submit" type="submit"> </form> <?php if($submit) { $input = $_POST['input']; $keyword=split("\n",$input); // other way //$keyword = explode("\n", $input); $number = count($keyword); for ($i = 0; $i < $number; $i++) { $array[$i] = md5($keyword[$i]); } } ?> If I spit out $array in another for loop, they aren't "right". Ideas? Quote Link to comment Share on other sites More sharing options...
btherl Posted July 5, 2007 Share Posted July 5, 2007 Try printing out urlencode($keyword[$i]) for each $i. That should show up any extra charaters that you can't see. Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 5, 2007 Share Posted July 5, 2007 try ths. <form action="<?=$PHP_SELF; ?>" method="post"> <textarea name="input" cols="50" rows="20"></textarea> <input name="submit" type="submit"> </form> <?php if($submit) { $input = $_POST['input']; $keyword=split("\n",$input); // other way //$keyword = explode("\n", $input); // $number = count($keyword); for ($i = 0; $i <count( $keyword); $i++) { $array[$i] = md5($keyword[$i]); } } ?> Quote Link to comment Share on other sites More sharing options...
r3dn4x Posted July 5, 2007 Author Share Posted July 5, 2007 Try printing out urlencode($keyword[$i]) for each $i. That should show up any extra charaters that you can't see. Aha! I found this: %0D Should I use a str_replace or something to get rid of it? Quote Link to comment Share on other sites More sharing options...
r3dn4x Posted July 5, 2007 Author Share Posted July 5, 2007 Anyone know how to strip it of %0D? Quote Link to comment Share on other sites More sharing options...
xyn Posted July 5, 2007 Share Posted July 5, 2007 i can only think of a long method. I'm sure there is shorter.. $NewHash = explode("%0D", $password); $NewHash = implode("", $NewHash); echo $NewHash; Quote Link to comment Share on other sites More sharing options...
btherl Posted July 11, 2007 Share Posted July 11, 2007 %0d is also known as "\r" or "control M", the carriage return character. $str = str_replace("\r", '', $str) should get rid of it. Quote Link to comment Share on other sites More sharing options...
Azu Posted July 11, 2007 Share Posted July 11, 2007 This will mess it up if the browser sends \r for newlines instead of \n Better to just replace the $keyword=split("\n",$input); With $keyword=split("\n",str_replace(array('\r\n','\n\r','\r'),'\n',$input)); This way there is no chance of it messing anything up. Quote Link to comment Share on other sites More sharing options...
btherl Posted July 11, 2007 Share Posted July 11, 2007 or $keyword=split("\n",str_replace(array("\r\n","\n\r","\r"),"\n",$input)); Quote Link to comment Share on other sites More sharing options...
Azu Posted July 11, 2007 Share Posted July 11, 2007 Aren't double quotes slower since they look for variables in the string? Quote Link to comment Share on other sites More sharing options...
btherl Posted July 11, 2007 Share Posted July 11, 2007 Yes they are slower, but double quotes also substitue backslash sequence such as "\r" and "\n". Those don't get replaced in single quotes. Quote Link to comment 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.