Created
January 23, 2019 16:25
-
-
Save pedrovasconcellos/7f68ba094f124280ea9e525731286693 to your computer and use it in GitHub Desktop.
DateVasc and Mask
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
| <?php | |
| function DateVasc($data){ | |
| if(count(explode("/",$data)) > 1){ | |
| return str_replace('/','-',implode("-",array_reverse(explode("/",$data)))); | |
| }elseif(count(explode("-",$data)) > 1){ | |
| return str_replace('-','/',(implode("/",array_reverse(explode("-",$data))))); | |
| } | |
| } | |
| echo ''; | |
| $dat ='1/11/2016'; | |
| echo DateVasc($dat); | |
| echo ' '; | |
| $dat = '2090-12-02'; | |
| echo DateVasc($dat); | |
| /// o codigo que eu fiz identifica o tipo da data e transforma no inverso. | |
| ?> | |
| <? | |
| 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; | |
| } | |
| $cnpj = "11222333000199"; | |
| $cpf = "00100200300"; | |
| $cep = "08665110"; | |
| $data = "10102010"; | |
| echo mask($cnpj,'##.###.###/####-##'); | |
| echo mask($cpf,'###.###.###-##'); | |
| echo mask($cep,'#####-###'); | |
| echo mask($data,'##/##/####'); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment