xml parsing error when data returning from curl_exec()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mithunmo
Forum Newbie
Posts: 6
Joined: Thu Mar 12, 2009 12:41 am

xml parsing error when data returning from curl_exec()

Post by mithunmo »

Hi All,

I have two files , send.php and recv.php.
I am using curl to execute the recv.php from send.php and recv.php sends back xml data to send.php. But when I display the output in send.php , it gives me error

XML Parsing Error: XML or text declaration not at start of entity
Location: http://localhost/quick/send.php
Line Number 3, Column 1:<?xml version="1.0" encoding="utf-8" ?>
^


I feel it is adding some extra characters when the xml data as string is coming from recv.php. How do i resolve this ?

Please help !

Code: Select all

 
 
//send.php 
<?php
 
$url = 'http://localhost/quick/recv.php';
$xmlfile = implode('', file('test.xml'));
 
 
$ch = curl_init();
 
 
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xmlfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($ch);
 
 
header("Content-Type: application/xml");
print "$result";
curl_close($ch);
?>
 
 
 
 
//recv.php 
 
<?php
 
$data = file_get_contents('php://input');
 
 
 $dat = '<?xml version="1.0" encoding="utf-8" ?>
        <FRMPing>
        <Test>0</Test>
        <Zip>92126</Zip>
        <GMI>2000</GMI>
        </FRMPing>';
        
 
echo "$dat";
 
?>
 
 
 
mithunmo
Forum Newbie
Posts: 6
Joined: Thu Mar 12, 2009 12:41 am

Re: xml parsing error when data returning from curl_exec()

Post by mithunmo »

No body checks my posts ? 8O
It will be great if some one can reply.
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: xml parsing error when data returning from curl_exec()

Post by temidayo »

try changing the charset=UTF-8 in the encoding

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
to charset=ISO-8859-1.

Do something like

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1" ?>
I hope it helps.
Post Reply