Zuker
Zuker

Reputation: 456

Warnings using curl

$dm_post = 'DATA=' . urlencode('<?xml version="1.0" encoding="ISO-8859-1"?><REPORTE><NROCTA>1098670</NROCTA><DETALLE><CONSULTA><CLAVE>123456</CLAVE><TIPO>1</TIPO><OPERACIONES><ID>123456789</ID></OPERACIONES></CONSULTA></DETALLE></REPORTE>');       

$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $dm_url);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $dm_post);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

$info = simplexml_load_string($buffer, 'SimpleXMLElement', LIBXML_NOCDATA);

print_r($info);

Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /var/www/domain.com/public_html/curl_test.php on line 15
Warning: simplexml_load_string(): 1 in /var/www/domain.com/public_html/curl_test.php on line 15
Warning: simplexml_load_string(): ^ in /var/www/domain.com/public_html/curl_test.php on line 15

any ideas? i dunno why i'm getting errors

Upvotes: 0

Views: 847

Answers (1)

Wiseguy
Wiseguy

Reputation: 20883

Looks like you need to set the cURL option CURLOPT_RETURNTRANSFER to true.

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

http://php.net/curl_setopt

Default behavior is for curl_exec() to output data directly. By turning on that option, it returns the data as a string instead, which appears to be what you're expecting.

Upvotes: 1

Related Questions