-2
Because the code below does not remove spaces, only line breaks?
$urlCorreios = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?
   nCdEmpresa=&
   sDsSenha=&
   nCdFormato=1&
   nVlDiametro=0&
   sCdMaoPropria=n&
   sCdAvisoRecebimento=n&
   nCdServico=" . $cod_servico . "&
   sCepOrigem=" . $cep_origem . "&
   sCepDestino=" . $cep_destino . "&
   nVlPeso=" . $peso . "&
   nVlAltura=" . $altura . "&
   nVlLargura=" . $largura . "&
   nVlComprimento=" . $comprimento . "&
   nVlValorDeclarado=" . $valor_declarado . "&
   StrRetorno=xml";
echo preg_replace('/[\n\r\t]/', '', $urlCorreios);
Just complementing, you used
[\n\r\t]. The brackets define a character class, and corresponds to any character within them. So this regex means: "a\nor one\ror one\t". None of these characters match the whitespace :-)– hkotsubo