<?php

$strs = array("aa","apple", "google", "abc12345", "asdddd"); 
foreach ($strs as $s) {
	$result = preg_replace('~(^.{3}|(?!^)\G)\K.~', "*", $s);
	echo $result . PHP_EOL;
}