1

Possible Duplicate:
Best XML Parser for PHP

I have a Php/ curl file

<?php
echo "Conversion Stats<br />"; 

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL,'http://login.leadkitchen.com/affiliates/api/4/reports.asmx/Conversions' );
$post_array = array(
       'affiliate_id' => '123',
    'api_key' => 'abc',
    'start_date' => '10/8/2012',
    'end_date' => '10/11/2012',
    'offer_id' => '123',
    'start_at_row' => '1',
    'row_limit' => '0',
    'sub_affiliate' => 'email'
);

//url-ify the data
foreach($post_array as $key=>$value) 
{ 
    $post_array_string .= $key.'='.$value.'&'; 
}
$post_array_string = rtrim($post_array_string,'&');
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_POST,count($post_array ));
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_array_string);
$response = curl_exec($ch);



print "$response";


?>

And possible XML response for this

<conversion_response>
<success>true</success>
<row_count>1</row_count>
<summary>
<price>22.26555000000000</price>
<currency_symbol>$</currency_symbol>
</summary>
<conversions>
<conversion>
<conversion_id>221D4853</conversion_id>
<conversion_date>2011-06-24T11:51:05.117</conversion_date>
<offer_id>100</offer_id>
<offer_name>$100 Bendy's Gift Card + Free Frosti</offer_name>
<campaign_id>1781</campaign_id>
<subid_1>111770</subid_1>
<subid_2/>
<subid_3/>
<subid_4/>
<subid_5/>
<price>15.0000</price>
<disposition>Voicemail matches name</disposition>
<test>false</test>
<currency_symbol>€</currency_symbol>
</conversion>
</conversions>
</conversion_response>

I actually need to display only conversion_id and price in the page. I don't want other results to be displayed on the page. How do I do this?

1
  • You do that by parsing the XML, see the link for the many options that exists. Commented Oct 11, 2012 at 2:49

1 Answer 1

1

You can use SimpleXMLElement to get the elements you want

$xml = new SimpleXMLElement($response);
echo "<pre>";
echo $xml->conversions->conversion->conversion_id, PHP_EOL;
echo $xml->conversions->conversion->price, PHP_EOL;

Output

221D4853
15.0000
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.