读取xml格式的天气预报的代码
<?PHP $apistr=file_get_contents("http://api.map.baidu.com/telematics/v2/weather?location=%E4%B8%8A%E6%B5%B7&ak=B8aced94da0b345579f481a1294c9094"); //获取xml内容 $apiobj=simplexml_load_string($apistr);//解析xml代码 $todayobj=$apiobj->results->result[0]->date;//读取星期 $weatherobj=$apiobj->results->result[0]->weather;//读取天气 $windobj=$apiobj->results->result[0]->wind;//读取风力 $temobj=$apiobj->results->result[0]->temperature;//读取温度 $contentStr = "上海\n{$todayobj}\n天气:{$weatherobj}\n风力:{$windobj}\n温度:{$temobj}"; echo $contentStr; ?>原文链接:https://www.f2er.com/xml/294746.html