Skip to content

Instantly share code, notes, and snippets.

@supercid
Created February 16, 2017 12:47
Show Gist options
  • Save supercid/1ddffc8080552d2acead7b15829195b7 to your computer and use it in GitHub Desktop.
Save supercid/1ddffc8080552d2acead7b15829195b7 to your computer and use it in GitHub Desktop.
Apply Mask
<?php
// src/AppBundle/Twig/MaskExtension.php
namespace AppBundle\Twig;
class MaskExtension
{
public function mask($value, $mask)
{
$maskared = '';
$value = (string) $value;
$k = 0;
for($i = 0; $i<=strlen($mask)-1; $i++){
if($mask[$i] == '#'){
if(isset($value[$k]))
$maskared .= $value[$k++];
}
else{
if(isset($mask[$i]))
$maskared .= $mask[$i];
}
}
return $maskared;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment