Q:

Xor function in PHP that corresponds to the one in C#

I would need to write in PHP a function that outputs me the same result just like the one in C# bellow. 
C#
public void Criptami()
   {
       szEncryptionKey = 200;
       szPlainText = input.text;
       StringBuilder szInputStringBuild = new StringBuilder(szPlainText);
       StringBuilder szOutStringBuild = new StringBuilder(szPlainText. Length);
       char Textch;
       for (int iCount = 0; iCount < szPlainText. Length; iCount++)
       {
           Textch = szInputStringBuild[iCount];
           Textch = (char)(Textch ^ szEncryptionKey);
           szOutStringBuild. Append(Textch);
       }
       Debug. Log(szOutStringBuild. ToString());
   }

For now I have tried using function that I have found in another dicussion here on Stackoverflow (Encrypt/decrypt with XOR in PHP), but having the same input, the final output is different. 
function xor_this($string) {

    // Let's define our key here
    $key = (200);

    // Our plaintext/ciphertext
    $text = $string;

    // Our output text
    $outText = '';

    // Iterate through each character
    for($i=0; $i<strlen($text); )
    {
        for($j=0; ($j<strlen($key) && $i<strlen($text)); $j++,$i++)
        {
            $outText .= $text{$i} ^ $key{$j};
            //echo 'i=' .  $i . ', ' . ' j=' .  $j . ', ' .  $outText{$i} . ' <br />'; // For debugging
        }
    }
    return $outText;
}

I was given the piece of code in C#, but for what I can gather - eventhough my knowldge of C# is almost non existant - it seems to me it should be operating in exactly the same way?  
Thanks a million for your time! 
EDIT: I have added input and output values
PHP
input: ciao
output: QYQ]
C#
input: ciao
output: «¡©§

A:

For some reason you are iterating through strlen($key).  I'm guessing you don't want to do that.  Here's what my PHP incompetent self manged to do:
function xor_this($string) {

// Let's define our key here
$key = (200);

// Our plaintext/ciphertext
$text = $string;

// Our output text
$outText = '';

// Iterate through each character
for($i=0; $i<strlen($text); $i++)
{
    $char = substr($text, $i, 1);
    $char = chr(ord($char) ^ $key);
    $outText .= $char;
}

return $outText;
}

With help from this SO answer.  And as shown in the other answer this can be done a lot more concisely:
function xor_this($string)
{
    $key = (200);
    for($i = 0; $i < strlen($string); $i++) 
            $string[$i] = chr(ord($string[$i]) ^ $key);

    return $string;
}

