2
The situation is the following, I have a script in PHP that makes CNPJ queries by the site of Receita Federal, but it is returning me some errors, I don’t really know if they’re mistakes.
HTML/PHP code
consulta.html
<html>
<head>
<title>CNPJ e Captcha</title>
</head>
<body>
<form method="post" action="processa.php">
<p><span class="titleCats">CNPJ e Captcha</span>
<br />
<input type="text" name="CNPJ" maxlength="19" required />
<b style="color: red">CNPJ</b>
<br />
<img src="getcaptcha.php" border="0">
<br />
<input type="text" name="CAPTCHA" maxlength="6" required />
<b style="color: red">O que vê na imagem acima?</b>
<br />
</p>
<p>
<input id="id_submit" name="enviar" type="submit" value="Consultar"/>
</p>
</form>
</body>
</html>
processa.php
<?php
require('funcoes.php');
$cnpj = $_POST['CNPJ'];
$captcha = $_POST['CAPTCHA'];
// pega html resposta da receita
$getHtmlCNPJ = getHtmlCNPJ($cnpj, $captcha);
if($getHtmlCNPJ)
{
// volova os dados em um array
$campos = parseHtmlCNPJ($getHtmlCNPJ);
var_dump($campos);
}
?>
funcoes.php
Like the code of funcoes.php
is too big and would disturb the question by leaving it too extensive, I will leave the link with the whole code, to see just click here
Now the result:
array(23) {
[0]=> string(18) "17.81X.03X/0X01-XX"
[1]=> string(10) "13/03/2013"
[2]=> string(58) "XXXXXXX - EMPRESA - ME"
[3]=> string(10) "TONER XXXXX"
[4]=> string(90) "X7.X1-X-01 - Comércio varejista especializado
de XXX"
[5]=> array(2) {
[0]=> string(67) "47.X1-X-02 -
Recarga de XXX para equipamentos de XXXXX "
[1]=> string(80)
"95.11-8-00 -Reparação e XXX de XX e de XXXXX XX"
}
[6]=> string(68) "230-5 - XXXXXXXXXXXXXX (DE NATUREZA EMPRESARIA)"
[7]=> string(37) "R GERONIMO DOS SANTOS (JD W XX)"
[8]=> string(2) "55"
[9]=> string(0) ""
[10]=> string(10) "09.X70-XXX"
[11]=> string(15) "NOVA XXXX"
[12]=> string(21) "SAO XXXXXX XXXX"
[13]=> string(2) "SP"
[14]=> string(26) "assessoriaprisma@XXX"
[15]=> string(14) "(11) 4X5-3XX08"
[16]=> string(5) "*****"
[17]=> string(5) "ATIVA"
[18]=> string(10) "13/03/2XXX"
[19]=> string(0) ""
[20]=> string(8) "********"
[21]=> string(8) "********"
["status"]=> string(2) "OK"
}
I don’t know if I’m right, but the result should be returned the same way it’s returned to the IRS. Excuse my ignorance in the subject and in the PHP language, but if this script is not wrong, how can I format this result?
Actually, for anyone who wants to see it live, try it yourself
What do you want?
I need the result to return formatted. How so? For example, a line indicating CNPJ {cnpj} another line indicating SOCIAL REASON {social reason}. This is just an example, summarizing, I need to format the result to understand it.
Note: I know that questions made to link base can and probably will receive downvotes, but I want to make it clear that my intention is good, since I am also providing a very good script of functional cnpj queries and do not intend to remove the link, unless that is removed by some third party
What’s the problem? What are the mistakes?
– rray
The "error" is in the result, I edited the question with what I want. @rray, I don’t know for sure, if this is exactly a mistake or the right result, but what I need is for the result to be format, or at least a guide for me to format myself. I could tell?
– João Victor Gomes Moreira
echo $campos[0] .' - '. $campos[4];
that?– rray
Yes that, the part about
array(23) { [0]=> string(18) "17.81X.03X/0X01-XX"
– João Victor Gomes Moreira
that ai the result of var_dump to get the values individually you need to do it manually as I put in the previous comment.
– rray
sorry @rray but, how could I do this?
– João Victor Gomes Moreira
vc need to put the desired Index(number) in the variable
campos
for example the 1 opinion the cnpj the 2 the company type and the 3 the name, to display them first remove thevar_dump($campos)
and putecho $campos[0] .' # '. $campos[2] . ' # '. $campos[3];
– rray
To make it easier to read this information in the future, use this:
echo '<pre>'; print_r($campos);
– rray
Friend, if it’s not too much, could you help me by way of answer? It would help too much and I believe that other people might have the same problem that I and with your help would solve theirs too
– João Victor Gomes Moreira
Was that the problem? can I answer yes
– rray
It was @rray, I just need the results to appear in a way that I can understand correctly and so I can include in a layout later. I appreciate the help
– João Victor Gomes Moreira