title: When selecting all, there is always a space at the end
body: <p>I have wrote this little script which generates a nice random password. The problem I am having is that when you open the page and select all + copy the text into the clipboard. There is always a space at the end even if I use the trim. Is there anyway to fix this?</p>
  
  <p>Tested using Firefox.</p>
  
  <p>UPDATE: Ok after testing with a <a href="http://jsfiddle.net/bXdmd/" rel="nofollow">jsfiddle</a> example this has nothing to do with PHP because I get the same issue here. This has the same problem of always adding a space at the end.</p>
  
  <pre><code>    &lt;?php
  function random_readable_pwd($length=10){
  
      // the wordlist from which the password gets generated 
      // (change them as you like)
      $words = 'AbbyMallard,AbigailGabble,AbisMal,Abu,Adella,TheAgent,AgentWendyPleakley,Zini';
  
      // Split by ",":
      $words = explode(',', $words);
      if (count($words) == 0){ die('Wordlist is empty!'); }
  
      // Add words while password is smaller than the given length
      $pwd = '';
      while (strlen($pwd) &lt; $length){
          $r = mt_rand(0, count($words)-1);
          $pwd .= $words[$r];
      }
  
      $num = mt_rand(1, 99);
       if ($length &gt; 2){
          $pwd = substr($pwd,0,$length-strlen($num)).$num;
      } else { 
          $pwd = substr($pwd, 0, $length);
      }
  
     $pass_length = strlen($pwd);
     $random_position = rand(0,$pass_length);
  
     $syms = "!@#%^*()-?";
     $int = rand(0,9);
     $rand_char = $syms[$int];
  
     $pwd = substr_replace($pwd, $rand_char, $random_position, 0);
  
      return $pwd;
  }
  ?&gt;
  &lt;html&gt;&lt;head&gt;&lt;title&gt;Password generator&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;&lt;?php echo random_readable_pwd(10); ?&gt;&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>