Created
March 27, 2015 12:42
-
-
Save bytefade/52676eca41760e476aed to your computer and use it in GitHub Desktop.
Mask PHP
This file contains hidden or 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
function mask($val, $mask) { | |
$maskared = ''; | |
$k = 0; | |
for($i = 0; $i<=strlen($mask)-1; $i++) | |
{ | |
if($mask[$i] == '#') | |
{ | |
if(isset($val[$k])) | |
$maskared .= $val[$k++]; | |
} | |
else | |
{ | |
if(isset($mask[$i])) | |
$maskared .= $mask[$i]; | |
} | |
} | |
return $maskared; | |
} | |
// uso: mask($value['cpf'], '###.###.###-##'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment