$lengeth=length($x) $temp=substr($x,6) //to get the first six digits $temp1=substr($x,($length-4),$length) //to get the last 4 for(int i=0;i<($length-10);i++) { $temp +='X'; } $temp +=$temp1;