title: PHP SHA1 gives different result than expected
body: <p>This really surprises me - this should be rather simple, but I can't figure out what the difference is.</p>
  
  <p>I have this function to generate a salt:</p>
  
  <pre><code>private function _generateSalt($max = 128)
  {
      $characterList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#¤%&amp;/()~";
      $i = 0;
      $salt = "";
      do {
          $salt .= $characterList{mt_rand(0,strlen($characterList)-1)};
           $i++;
      } while ($i &lt; $max);
      return $salt;
  }
  </code></pre>
  
  <p>Pretty basic(?)</p>
  
  <p>And trying to create a SHA1 hash from this, gives me a different result what I would expect:</p>
  
  <pre><code>$salt = $this-&gt;_generateSalt();
  $password = $salt.$password;
  echo sha1($password);
  </code></pre>
  
  <p>$password is a string generated by user input.
  The echoed hashed string is wrong. And I don't know why.</p>
  
  <p><code>var_dump($password);</code> after prepending the salt gives me the expected string size - copy and paste the result to an online SHA1 service or hashing the string through MySQL CLI gives the correct result. It's like there's something invisible in the $password variable I wan't to hash. But how can I find out why this is happening? var_dump(), trim() and comparing results haven't gotten me anywhere?</p>