<?php
function maior($x)
{
    $index = -1;
    for ($i=0;$i<strlen($x);$i++)
    {
        if ($ultimo != $x[$i])
        {
            $ultimocount = $count;
            $count = 0;
            $ultimo = $x[$i];
        }
        else
        {
            $count++;
            if ($count > $ultimocount)
                $index = strpos($x, $x[$i]);
        }
    }
    return $index;
}

$n = "abbcccddddeeeeeefffffffffggg";
echo maior($n);