Treatment of encoding in XML

1

I'm trying to make a request for a URL that contains a return on XML with the function simplexml_load_file('url') and I only get false when I debug using var_dump .

$xml = simplexml_load_file('http://www.cinemark.com.br/programacao.xml');

var_dump($xml);

Return:

bool(false)

What other method can I use to handle XML out of this function, and what would be the "correct" application for this function?

After activating the display of errors in php, I get the following warning:

  

Warning: simplexml_load_file (): link : parser error: Start tag expected, '<' not found

     

Warning: simplexml_load_file (): ...

I think it's an encoding problem, I've tried to put the header() function and use chatset=utf-8 but the error is shown above.

After using mb_detect_encoding I get: "UTF-8"

    
asked by anonymous 19.03.2017 / 16:37

1 answer

0

It seems to me that the server is always forcing data compression, leaving the data flat only when the client shows it does not support it.

You can tell the server that it does not support data compression and receive the XML. The following code does this:

<?php

header('Content-Type: text/html; charset=ISO-8859-1');

$curl = curl_init('http://www.cinemark.com.br/programacao.xml');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

/* Esta Opção que resolve o problema */
curl_setopt($curl, CURLOPT_ENCODING, 'identity');

$conteudo = curl_exec($curl);

var_dump($conteudo);

$xml = simplexml_load_string($conteudo);

var_dump($xml);
    
20.03.2017 / 15:17