Twig/Extensionuser/Passwordmask.php を以下のように作成します
class Twig_Extensionuser_Passwordmask extends Twig_Extension
{
public function getFilters()
{
return array('passwordmask' => new Twig_Filter_Method($this, 'passwordmask'));
}
public function passwordmask($string)
{
if (strlen($string) == 1) {
return '*';
}
$out = '';
for ($i = 0; $i < strlen($string); $i++) {
if ($i + 1 == strlen($string)) {$out .= $string[$i];} else { $out .= '*';}
}
return $out;
}
public function getName()
{
return 'passwordmask';
}
}
使い方
{{ 'aiueo123456' | passwordmask }}
表示結果
**********6