- substr: documentation ( source)
- str_pad: documentation ( source)
<?php
$string = "abcdefgh";
$firstChar = substr($string,0,1);
$lastChar = substr($string,-1);
$stars = str_pad("",strlen($string) -2, "*");
$output = $firstChar . $stars . $lastChar;
echo $output;