extract url from xml response and redirect
I'm using curl to post form data in xml string. The xml response is <redirect_url>www.xxxxx.com</redirect_url>
. Could anyone help me to extract this url and redirect the user to it? Thanks.
Sorry been away... Thanks for the responses. The code is:
// create a new cURL resource
$ch = curl_init('http://www.zzz.com/');
// set r appropriate options
$strXML = "<lead> <applicant> <title>".$title."</title> <fname>".$fname."</fname> <lname>".$lname."</lname> <email>".$email."</email> <dob>".$dob."</dob> </lead>";
echo $strXML;
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, '1'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, array('lead'=>$strXML)); $strResult = curl_exec($ch); // close cURL resource, and free up system resources
echo $strResult;
curl_close($ch);
Example Response:
<result>
<posting_error>0</posting_error>
<valid_partner>1</valid_partner>
<redirect_url>www.xxx.com</redirect_url>
</result>
使用SimpleXML
和header
:
$xml = new SimpleXMLElement($xml_response);
header('Location: ' . $xml->redirect_url);
链接地址: http://www.djcxy.com/p/35840.html
上一篇: XML>仅在源代码中使用PHP
下一篇: 从xml响应中提取url并重定向