title: XOR string in PHP with key
body: <p>I need to XOR a string/text in PHP the base64 encode it, but something goes wrong:</p>
  
  <pre><code>&lt;?php
  
  $mustget = 'Kw4SCQ==';
  $string = 'Josh';
  
  echo("Must get: " . $mustget . "\n");
  echo("We got: " . base64_encode(xor_this($string)) . "\n");
  
  function xor_this($text) {
      $key = 'frtkj';
      $i = 0;
      $encrypted = '';
      foreach (str_split($text) as $char) {
          $encrypted .= chr(ord($char) ^ ord($key{$i++ % strlen($key)}));
      }
      return $encrypted;
  }
  
  ?&gt;
  </code></pre>
  
  <p>I get the following result, but I need to get the "$mustget" one:</p>
  
  <pre><code>Must get: Kw4SCQ==
  We got: LB0HAw==
  </code></pre>
  
  <p>What do I do wrong?</p>