Jump to content

md5() multiple strings?


r3dn4x

Recommended Posts

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?

Link to comment
Share on other sites

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]);
   }
}

?>

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

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.