猿问

使用php以编程方式传递soap值

我有以下php脚本来更新xml值:


//The XML string that you want to send.

$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>

<reminder>

    <date>2019-20-02T10:45:00</date>

    <heading>Meeting</heading>

    <body>Team meeting in Boardroom 2A.</body>

</reminder>';



//The URL that you want to send your XML to.

$url = 'http://localhost/xml';


//Initiate cURL

$curl = curl_init($url);


//Set the Content-Type to text/xml.

curl_setopt ($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));


//Set CURLOPT_POST to true to send a POST request.

curl_setopt($curl, CURLOPT_POST, true);


//Attach the XML string to the body of our request.

curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);


//Tell cURL that we want the response to be returned as

//a string instead of being dumped to the output.

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);


//Execute the POST request and send our XML.

$result = curl_exec($curl);


//Do some basic error checking.

if(curl_errno($curl)){

    throw new Exception(curl_error($curl));

}


//Close the cURL handle.

curl_close($curl);


//Print out the response output.

echo $result;

但是,我打算做的是,我想使用动态值制作$ xml,已经尝试过这样的事情:


$date= $_POST['datevalue'];

$heading= $_POST['meetingvalue'];

$body= $_POST['bodycontent'];


$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>

<reminder>

    <date>{$date}</date>

    <heading>{$date}</heading>

    <body>{$date}</body>

</reminder>';

不幸的是,上面的代码无法正常工作,似乎{$ date}并没有发送任何东西来休息SOAP。


任何人都有解决此问题的经验,


陪伴而非守候
浏览 145回答 2
2回答

红糖糍粑

我不是这方面的专家,所以请给个建议,尝试使用双引号,如下所示:$xml = "<?xml version='1.0' encoding='ISO-8859-1'?><reminder>&nbsp; <date>{$date}</date>&nbsp; <heading>{$date}</heading>&nbsp; <body>{$date}</body></reminder>";希望能有所帮助

守着星空守着你

替换字符串呢?$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>&nbsp; &nbsp; <reminder>&nbsp; &nbsp; &nbsp; &nbsp; <date>%s</date>&nbsp; &nbsp; &nbsp; &nbsp; <heading>%s</heading>&nbsp; &nbsp; &nbsp; &nbsp; <body>%s</body>&nbsp; &nbsp; </reminder>';$message = sprintf($xml, $date, $heading, $body);无论如何,完整的动态XML方法可以使用DomDocument类。$doc = new DomDocument('1.0', 'iso-8859-1');$reminder = $doc->createElement('reminder');$date = $doc->createElement('date', $dateValue);$reminder->appendChild($date);$heading = $doc->createElement('heading', $headingValue);$reminder->appendChild($heading);$body = $doc->createElement('body', $bodyValue);$reminder->appendChild($body);$doc->appendChild($reminder);$xmlString = $doc->saveXML();该$xmlString变量将您的xml树包含为带有动态值的字符串。
随时随地看视频慕课网APP
我要回答