마스킹처리 , masking

1
<?php
function maskingString($str,$divBy=3){
preg_match_all('/./u',$str,$ss);
$ss = isset($ss[0])?$ss[0]:array();
$len = count($ss);
$lenBy =$len/max(1,$divBy);
$lenSt =  max(1,floor($lenBy));
$lenMd=$len==2?2:min($len,$len-$lenSt);
for($i=$lenSt,$m=$lenMd;$i<$m;$i++){
$ss[$i] = '*';
}
return implode('',$ss);
}



echo maskingString('a'),"\n";
echo maskingString('ab'),"\n";
echo maskingString('abc'),"\n";
echo maskingString('abcd'),"\n";
echo maskingString('abcde'),"\n";
echo maskingString('abcdef'),"\n";
echo maskingString('abcdefg'),"\n";
echo maskingString('abcdefgh'),"\n";
echo maskingString('abcdefghi'),"\n";
echo maskingString('abcdefghij'),"\n";
echo maskingString('abcdefghijk'),"\n";
echo maskingString('abcdefghijkl'),"\n";
echo maskingString('abcdefghijklm'),"\n";
echo maskingString('abcdefghijklmn'),"\n";

echo maskingString('한'),"\n";
echo maskingString('한글'),"\n";
echo maskingString('한글테'),"\n";
echo maskingString('한글테스'),"\n";
echo maskingString('한글테스트'),"\n";
echo maskingString('한글테스트 '),"\n";
echo maskingString('한글테스트 잘'),"\n";
echo maskingString('한글테스트 잘되'),"\n";
echo maskingString('한글테스트 잘되나'),"\n";
echo maskingString('한글테스트 잘되나?'),"\n";

echo maskingString('한1'),"\n";
echo maskingString('한1글2'),"\n";
echo maskingString('한1글2테3'),"\n";
echo maskingString('한1글2테3스4'),"\n";
echo maskingString('한1글2테3스4트5'),"\n";
echo maskingString('한1글2테3스4트5 6'),"\n";
echo maskingString('한1글2테3스4트5 6잘7'),"\n";
echo maskingString('한1글2테3스4트5 6잘7되8'),"\n";
echo maskingString('한1글2테3스4트5 6잘7되8나9'),"\n";
echo maskingString('한1글2테3스4트5 6잘7되8나9?'),"\n";

echo maskingString('abcdefghijklmn',0),"\n";
echo maskingString('abcdefghijklmn',1),"\n";
echo maskingString('abcdefghijklmn',2),"\n";
echo maskingString('abcdefghijklmn',3),"\n";
echo maskingString('abcdefghijklmn',4),"\n";
echo maskingString('abcdefghijklmn',5),"\n";
echo maskingString('abcdefghijklmn',6),"\n";
echo maskingString('abcdefghijklmn',7),"\n";
echo maskingString('abcdefghijklmn',8),"\n";
echo maskingString('abcdefghijklmn',9),"\n";
echo maskingString('abcdefghijklmn',10),"\n";


a
a*
a*c
a**d
a***e
ab**ef
ab***fg
ab****gh
abc***ghi
abc****hij
abc*****ijk
abcd****ijkl
abcd*****jklm
abcd******klmn
한*
한*테
한**스
한***트
한글**트 
한글*** 잘
한글****잘되
한글테***잘되나
한글테****되나?
한*
한**2
한1**테3
한1****스4
한1글****4트5
한1글2****트5 6
한1글2****** 6잘7
한1글2테******6잘7되8
한1글2테3******잘7되8나9
한1글2테3*******7되8나9?
abcdefghijklmn
abcdefghijklmn
abcdefghijklmn
abcd******klmn
abc********lmn
ab**********mn
ab**********mn
ab**********mn
a************n
a************n
a************n

댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
제목 작성자 날짜
공대여자
공대여자
mins01
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자
공대여자