ideone
$str = "aaaaaaaaaa";
$carater="-";
$apartir=3;
$ate=7;
$ambos="ambos";
$entre="entre";
$compr=strlen($str);
if ($apartir==3){
$nome=substr($str, $compr-$apartir, $compr);
$right = str_pad($nome, $compr, $carater, STR_PAD_RIGHT);
}
if ($ate==7){
$nome=substr($str, $compr-$apartir, $compr);
$left = str_pad($nome, $compr, $carater, STR_PAD_LEFT);
}
if($ambos=="ambos"){
$nome=substr($str, $ate, $compr);
$both = str_pad($nome, $compr, $carater, STR_PAD_BOTH);
}
echo $right;
echo "\n";
echo $left;
echo "\n";
echo $both;
echo "\n";
$quant=2;
$parts = str_split($str, $quant);
$inicio = $fim = $parts[0];
$aux=substr($str,$quant*2,$compr);
$compl=str_replace("a",$carater,$aux);
$meio=$inicio.$compl.$fim;
echo $meio;
References:
strlen
substr
str_pad
str_split