php接受xml和发送(post)xml
接收xml:
$xml = file_get_contents('php://input');
发送(post):
$xml_data = <xml>...</xml>";
$url = http://dest_url;
$header[] = "Content-type: text/xml";//定义content-type为xml
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
$response = curl_exec($ch);
if(curl_errno($ch))
{
print curl_error($ch);
}
curl_close($ch);
或者:
$fp = fsockopen($server, 80);
fputs($fp, "POST $path HTTP/1.0\r\n");
fputs($fp, "Host: $server\r\n");
fputs($fp, "Content-Type: text/xml\r\n");
fputs($fp, "Content-Length: $contentLength\r\n");
fputs($fp, "Connection: close\r\n");
fputs($fp, "\r\n"); // all headers sent
fputs($fp, $xml_data);
$result = '';
while (!feof($fp)) {
$result .= fgets($fp, 128);
}
return $result;
相关文档:
function redirect($url, $msg)
{
echo $msg."</br>\n";
echo "<a href=\"".$url."\">如果没有跳转,请点这里跳转</a>\n";
echo "<script language=\"javascript\">se ......
PHP站点的在线教程已经很棒了。在那里还有一些其他教程的链接。而本文的该部分将让你对PHP熟悉一点。我不可能做到没有任何遗漏,我的目的只在于能让你迅速开始你的PHP编程。
2.1 首要条件
你首先必须要有一个正在工作着的支持PHP的web服务器。我假定在你的服务器上所有PHP文件的扩展名为.php3。
2.2 PHP的安装
生 ......
需求:
需要对两个目录中的文件内容进行查找替换,两个目录查找替换的内容不一样。
实现中注意几点:
(1)函数递归调用,来检索子目录;
(2)函数名可以以参数形式传递;
(3)用?进行非贪婪匹配;
......
<?php
if(empty($_GET[submit]))
{
?>
<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF']?>?submit=1" method="post">
<input name="filename" type="file">
<input type="submit" value="确定上传">
</form>
<?php
}
else{
......
JSON 是一项旨在允许中间件创建使用 JavaScript 固有格式的对象的协议。它最强大的属性是它是一种轻量级协议。简单处理 RSS 聚合或 recipe 列表时,您不需要在 JavaScript 中使用 XML 的全部功能。不需要验证格式或确保严格的数据键入。
编码和解码
有两个函数用于 JSON:encode 和 decode。第一个函数将把任意类型的数 ......