代码如下 | 复制代码 |
$xml = < < < xml out: [command_name] => provision ) ) |
$url="http://mb.111com.net/ws.php?q=content";
$dom = new domdocument();
$dom->load($url);
//print"
";
//print( $dom->savexml());
$dictarray = $dom->getelementsbytagname("dict");
foreach( $dictarray as $dict ) {
$key = $dict->getelementsbytagname("key");
$key=$key->item(0)->nodevalue;
$key= iconv("utf-8","gb2312",$key); //注意要转码对于中文,因为xml默认为utf-8格式
echo ("***输出>key>的内容:****:".$key);
$lang = $dict->getelementsbytagname("lang");
$lang = utf8_decode($lang->item(0)->nodevalue);
echo "
";
echo ("***输出>lang>的内容:****:".$lang);
}
方法三$fp=fsockopen("xxx.xxx.com", 80, $errno, $errstr, 30);
if($fp){
$out = "get /abc.xml?key=value http/1.1 ";
$out .= "host: xxx.xxx.com ";
$out.= 'user_agent: xml-rpc client ';
$out.='content-type: text/xml ';
$out .= "connection: close ";
fwrite($fp,$out);
while(!@feof($fp)){
$result.=@fgets($fp,1024);
}
fclose($fp);
}
echo $result;