SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
-
Jun 30, 2004, 03:56 #1
- Join Date
- Jun 2004
- Location
- Greenock
- Posts
- 53
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Assigning embedded XML to a variable in PHP
First, I'd like to say hello! to everybody out there.
OK, down to business. I've been working with XML for 3-4 months, using PHPs Sablatron to transform the data. So far, this has simply been a case of using cURL to to fetch the XML which is then assigned to a variable (eg $result). This is then transformed using Sablatron, with the result placed into another variable and ECHO-ed into the browser.
At the moment I'm trying to do this to a feed which seems to behave a little differently. When I execute the cURL it returns an XML stream which needs to be read into an XML object for transforming. This is where I'm getting lost, as simply assigning a variable doesn't work. The only way I can see the XML is by right-click/viewsource. ECHOing the variable simply returns a value of '1', which I'm assuming is just the boolean 'true'. Here is the code I'm using:
<?php
$oper='COS';
$abta=J568X;
$pass='essex';
$holref='GAN20ANZM2';
$dept='LGW';
$depdate='14SEP04';
$nights='07';
$adults='2';
$children='0';
$infants='0';
$siteid='TESTXML';
$varsent='siteid='.$siteid.'&oper='.$oper.'&abta='.$abta.'&pass='.$pass.'&holref='.$holref.'&dept='.$dept.'&depdate='.$depdate.'&nights='.$nights.'&adults='.$adults.'&children='.$children.'&infants='.$infants;
// echo $varsent;
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL,"http://195.188.244.12/xmltier3/xml_rooms.asp");
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $varsent);
$result=curl_exec($ch);
curl_close($ch);
echo 'result - '.$result;
?>
I've googled on XML+object+php, but didn't find anything useful in the results. I've also had a search throught his forum with the same level of success. Thanks for taking the time to read this.
Brian
-
Jul 1, 2004, 06:26 #2
- Join Date
- Jun 2004
- Location
- Greenock
- Posts
- 53
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've found the solution. I only needed to add the following line to the cURL:
HTML Code:curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
Brian
Bookmarks