压缩函数从字符串中删除双字母(PHP)

I need to take every double letter occurrence away from a word. (I.E. "attached" have to become: "aached".)

I wrote this function:

function strip_doubles($string, $positions) {
for ($i = 0; $i < strlen($string); $i++) {
    $stripped_word[] = $string[$i];
}   
foreach($positions['word'] as $position) {      
    unset($stripped_word[$position], $stripped_word[$position + 1]);
}
$returned_string= "";   
foreach($stripped_words $key => $value) {
    $returned_string.= $stripped_words[$key];
}
return $returned_string;
}

where $string is the word to be stripped and $positions is an array containing the positions of any first double letter.

It perfectly works but how would a real programmer write the same function... in a more condensed way? I have a feeling it could be possible to do the same thing without three loops and so much code.

Non-regex solution, tested:

$string = 'attached';
$stripped = '';
for ($i=0,$l=strlen($string);$i<$l;$i++) {
    $matched = '';
    // if current char is the same as the next, skip it
    while (substr($string, $i, 1)==substr($string, $i+1, 1)) {
        $matched = substr($string, $i, 1);
        $i++;
    }
    // if current char is NOT the same as the matched char, append it
    if (substr($string, $i, 1) != $matched) {
        $stripped .= substr($string, $i, 1);
    }
}
echo $stripped;

You should use a regular expression. It matches on certain characteristics and can replace the matched occurences with some other string(s).

Something like

$result = preg_replace('@([a-zA-Z]{1})\1@i', '', $string);

Should work. It tells the regexp to match one character from a-z followed by the match itself, thus effectively two identical characters after each other. The @ mark the start and end of the regexp. If you want more characters than just a-z and A-Z, you could use other identifiers like [a-ZA-Z0-9]{1} or for any character .{1} or for only Unicode characters (including combined characters), use \p{L}\p{M}*

The i flag after the last @ means 'case insensitive' and will instruct the regexp to also match combinations with different cases, like 'tT'. If you want only combinations in the same case, so 'tt' and 'TT', then remove the 'i' from the flags.

The '' tells the regexp to replace the matched occurences (the two identical characters) with an empty string.

See http://php.net/manual/en/function.preg-replace.php and http://www.regular-expressions.info/