We help IT Professionals succeed at work.

php Curl XML reponse - how do I get the three values out of the xml parsable html string:

mavmanau
mavmanau asked
on
484 Views
Last Modified: 2012-08-13
Hi,

Many thanks for your assistance it is appreciated.  Essentially I am uploading some data and getting a reponse back.

This is my current code for uploading.

$ch = curl_init( $url );
  ini_set('display_errors', 'On');
error_reporting(E_ALL);
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );
curl_close($ch);
 
  //Parse the XML
  $phpobject = simplexml_load_string($response);
 
  foreach($phpobject->attributes() as $name=>$attr) {
    $res[$name]=$attr;
  }
  print_r($phpobject);
 // $PaymentDataResponse = new SimpleXMLElement($response);
 // echo $PaymentDataResponse->PaymentURL;
?>

and this is the response:

SimpleXMLElement Object ( [body] => SimpleXMLElement Object ( [form] => SimpleXMLElement Object ( [input] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => hidden [name] => SessionStored [value] => True ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => hidden [name] => SessionStoredError [value] => ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [type] => hidden [name] => SST [value] => f39796a6-bf4c-451a-9d07-acfe2e3e51ad ) ) ) ) ) )

How do I go about extracting just the SST and the SessionStored and the SessionStorederror instead of the whole lot.

your help is most appreciated.
Comment
Watch Question

Most Valuable Expert 2011
Author of the Year 2014

Commented:
I can help with this, but I need to have the test data from $response that was used to create the object.  Please get the XML string for me and post it in the code snippet, thanks. ~Ray
mavmanauNetwork Engineer/Sysadmin

Author

Commented:
Hi,

How do I do that?

I tried
print 'This is the response: '.$response.'<br>'; but it doesn't show anything.
mavmanauNetwork Engineer/Sysadmin

Author

Commented:
essentially what is supposed to be returned is a simple html page with three hidden controls as per the output above.
mavmanauNetwork Engineer/Sysadmin

Author

Commented:
This is the exact sample data that is supposed to be returned.

<html>
<body>
<form>
<input type="hidden" name="SessionStored" Value="True" />
<input type="hidden" name="SessionStoredError" Value="" />
<input type="hidden" name="SST" Value="876jhgjhgd66dfhd88" />
</form>
</body>
</html>
Most Valuable Expert 2011
Author of the Year 2014

Commented:
The HTML posted here is not quite the same information as the information in the object shown above.  And XML can be confusing because your browser will look at it as if it contains unknown HTML tags, so you will not see anything useful until you use "view source"

Let's try this.   Run this part, then use "view source" to get the XML.  Copy that and paste it here in a code snippet.  Thanks, ~Ray

$ch = curl_init( $url );
  ini_set('display_errors', 'On');
error_reporting(E_ALL);
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );
var_dump($response);
mavmanauNetwork Engineer/Sysadmin

Author

Commented:
Hi,

So this is OK?

"<html><body><form><input type="hidden" name="SessionStored" value="True" /><input type="hidden" name="SessionStoredError" value="" /><input type="hidden" name="SST" value="e41029a0-aa74-42b4-b4ed-b769763f38de" /></form></body></html>"

thank you for your help! I was starting to do my head in somewhat googling everything I could think of.
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
mavmanauNetwork Engineer/Sysadmin

Author

Commented:
Dude - You are a legend!! thank you very much!  Your help is so appreciated!
mavmanauNetwork Engineer/Sysadmin

Author

Commented:
Excellent help!! very prompt and awesome!
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Thanks for the points and for your kind words!  Best of luck with your project, ~Ray

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.