Accent error when using Curl

Asked

Viewed 475 times

1

Good afternoon, all right?

I’m trying to pull some information via Url of the post office site, however it is returning me but with accentuation error, would have some way to change the header that is coming from there to fix this accent problem?

I’m pulling this way:

<?php

$codigoRastreio = urlencode($_GET['cod']);
$post = array('Objetos' => $codigoRastreio);
// iniciar CURL
$ch = curl_init();
// informar URL e outras funções ao CURL
curl_setopt($ch, CURLOPT_URL, "http://www2.correios.com.br/sistemas/rastreamento/resultado_semcontent.cfm");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($post));
// Acessar a URL e retornar a saída
$output = curl_exec($ch);
// liberar
curl_close($ch);
// Imprimir a saída
echo $output;

?>

1 answer

1

Already managed to fix, follow the updated code:

$codigoRastreio = urlencode($_GET['cod']);
$post = array('Objetos' => $codigoRastreio);
// iniciar CURL
$ch = curl_init();
// informar URL e outras funções ao CURL
curl_setopt($ch, CURLOPT_URL, "http://www2.correios.com.br/sistemas/rastreamento/resultado_semcontent.cfm");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($post));
// Acessar a URL e retornar a saída
$output = curl_exec($ch);
// liberar
curl_close($ch);
// Imprimir a saída
echo utf8_encode($output);
  • 2

    Don’t you want to comment on what you’ve changed in the code that works? Without anything written forces others to try to compare the entire programs - and it doesn’t help much who has the same question.

  • Of course I comment yes what I did, it only includes this code urlencode() where I am pulling the get and includes this utf8_encode() that was the main responsible for working.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.