Created
February 16, 2017 12:47
-
-
Save supercid/1ddffc8080552d2acead7b15829195b7 to your computer and use it in GitHub Desktop.
Apply Mask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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