Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Receita Federal - Cadastro Nacional de Pessoa Jurídica
- * @package Harverst
- * @version 2019-11-29
- */
- # Complementa o número do documento com ZERO à esquerda
- function cnpj_completar($input) {
- return (string) str_pad($input, 12, '0', STR_PAD_LEFT);
- }
- # Formatação com máscara de entrada
- function cnpj_formatar($input, $output = '##.###.###/####-##') {
- for($i = 0, $l = strlen($input); $i < $l; ++$i) {
- $output[strpos($output, '#')] = $input[$i];
- }
- return $output;
- }
- # Obtém os digitos verificadores
- function cnpj_verificador($input) {
- $first = (
- $input[11] * 9 + $input[10] * 8 +
- $input[9] * 7 + $input[8] * 6 +
- $input[7] * 5 + $input[6] * 4 +
- $input[5] * 3 + $input[4] * 2 +
- $input[3] * 9 + $input[2] * 8 +
- $input[1] * 7 + $input[0] * 6
- ) % 11;
- if($first == 10) $first = 0;
- $second = (
- $first * 9 + $input[11] * 8 +
- $input[10] * 7 + $input[9] * 6 +
- $input[8] * 5 + $input[7] * 4 +
- $input[6] * 3 + $input[5] * 2 +
- $input[4] * 9 + $input[3] * 8 +
- $input[2] * 7 + $input[1] * 6 +
- $input[0] * 5
- ) % 11;
- if($second == 10) $second = 0;
- $controller = $first * 10 + $second;
- if($controller === 0) $controller = '00';
- if($controller > 0 && $controller < 10) $controller = '0' . $controller;
- return $controller;
- }
Advertisement
Add Comment
Please, Sign In to add comment