用PHP发送textarea形式的xml文件

时间:2014-03-31 19:06:08

标签: php html xml curl

我需要将位于服务器上的xml文件的内容发送到文本表单。 我尝试在PHP中使用curl方法,但我不知道如何从xml文件中读取内容并将其保存到变量。怎么了?

此处 PHP代码:

if ($model->getSOrderStatuses()->id == 1) {
$xml = new XMLWriter();
$xml->openMemory();
$xml->openURI('uploads/files/orders.xml');
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement("order"); //start root
$xml->writeElement("id", $model->getId());
$xml->writeElement("date", gmdate("Y-m-d\/H:i:s", $model->getDateCreated()));
$xml->writeElement("customer", $model->getUserFullName());
$xml->writeElement("phone", $model->getUserPhone());
$xml->writeElement("email", $model->getUserEmail());
$xml->writeElement("delivery_type", $model->getSDeliveryMethods()->getId());
$xml->writeElement("delivery_adress", $model->getUserDeliverTo());
$xml->writeElement("payment_type", $model->getSPaymentMethods()->getId());
$xml->writeElement("comment", $model->getUserComment());
$xml->startElement("products");  //open element
foreach ($model->getSOrderProductss() as $sOrderProduct) {
$total = $total + $sOrderProduct->getQuantity() * $sOrderProduct->toCurrency();
$product = $sOrderProduct->getSProducts();
$xml->startElement("row");       //open element
$xml->writeAttribute("code", $product->getUrl());
$xml->writeAttribute("qty", $sOrderProduct->getQuantity());
$xml->writeAttribute("price", $sOrderProduct->toCurrency());
$xml->writeAttribute("sum", $sOrderProduct->getQuantity() * $sOrderProduct-    >toCurrency());
$xml->endElement();  //close element
}
$xml->endElement();  //close element
$xml->writeElement("sum", my_money_format('',$total));
$xml->endElement();  //close root
$xml->flush();
$xmlorder = 'uploads/files/orders.xml';
$ch = curl_init('http://pathtomyserver/?action=newor');
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlorder);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER,0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
echo($xmlorder);
$info=curl_getinfo($ch);  
curl_close($ch);
}
}

形式:

>>链路

1 个答案:

答案 0 :(得分:1)

你可以用这个

$xml = file_get_contents("path/to/xml.xml");

然后输出到textarea

<textarea name="xml"><?php echo $xml; ?>