Skip to content

Instantly share code, notes, and snippets.

@dca
Created October 23, 2012 04:00
Show Gist options
  • Select an option

  • Save dca/3936554 to your computer and use it in GitHub Desktop.

Select an option

Save dca/3936554 to your computer and use it in GitHub Desktop.
PHP Name2Star
<?php
/**
* NameToStar function
*
* @return 打過星號的字串
* @author
**/
function NameToStar($name)
{
$len=mb_strlen($name,'UTF-8');
$startnum=0;
for ( $xyz = 0 ; $xyz < $len ; $xyz++ )
{
if ( ($xyz % 2)=='1' )
{
$txtlen=strlen(mb_substr($name,$xyz,1,'UTF-8'));
$name=substr_replace($name, '*', $startnum,$txtlen);
$startnum+=1;
}
else
{
$startnum+=strlen(mb_substr($name,$xyz,1,'UTF-8'));
}
}
return $name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment