-1
I have the html form:
<div id="formulario">
<form method="POST" action="Controller/jsonTeste.php">
CEP: <input type="text" name="cep" placeholder="Insira o cep" required/>
<input type="submit" /></p>
</form>
</div>
And the php file:
<?php
$formCEP = $_POST['cep'];
$formCEP = preg_replace("/[^0-9]/", "", $formCEP);
$url = file_get_contents('http://viacep.com.br/ws/$formCEP/json/');
?>
When passing the $formCEP variable to the ULR: http://viacep.com.br/ws/$formCEP/json/, I receive a "Warning" as response, but when typing a valid zip code for the URL, it is accepted as valid. How to resolve?
Which Warning you get?
– gmsantos
I think the problem is only the use of the variable $formCEP Concatenates it into the URL $url = file_get_contents('http://viacep.com.br/ws/' . $formCEP . '/json/');
– Jandelson Oliveira