【发布时间】:2011-06-10 00:48:10
【问题描述】:
这是我的 php 代码:
<?php
if (array_key_exists("site", $_GET) && $_GET["site"] != "" )
{
$url = $_REQUEST['site'];
$url = " http://api.mywot.com/0.4/public_query2?target=";
$result= $url.urlencode($url);
$process = curl_init($result);
//init curl connection
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER,1);
curl_setopt($process,CURLOPT_CONNECTTIMEOUT,1);
$resp = curl_exec($process);
curl_close($process);
header('Content-Type: text/xml');
$xml = new SimpleXMLElement($resp);
}
?>
假定的 xml:
<?xml version="1.0" encoding="UTF-8"?>
<query target="example.com">
<application name="0" r="89" c="44"/>
<application name="1" r="89" c="46"/>
<application name="2" r="92" c="47"/>
<application name="4" r="93" c="48"/>
</query>
我知道怎么读这种xml文件
<Status>
<code>200</code>
<request>geocode</request>
</Status>
$status = (int) $xml->Status->code;
上面的xml中有application等重复的标签,有的怎么读?
【问题讨论】:
-
旁注:你不是写过
$url的值吗?不应该是$result= $url.urlencode($_REQUEST['site']);之类的吗? -
是的,对不起,这是一个错误
-
(sidenote) 基于 libxml 的扩展(如 SimpleXml)可以与自定义流上下文一起使用,因此技术上不需要使用 CURL
标签: php xml curl xmlhttprequest