Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XML到PHP变量_Php_Xml_Variables_Xml Parsing - Fatal编程技术网

XML到PHP变量

XML到PHP变量,php,xml,variables,xml-parsing,Php,Xml,Variables,Xml Parsing,我的xml php脚本有问题。 XML文档: 我想要一个名为:$temp的变量中的温度,如果您正在获取输出 echo$temp->temperature,,$temp->windSpeed,PHP_EOL 由此,您可以得到如下所示的温度值 PHP代码: $temp_array = array(); $tempt_str = '' $i = 0; foreach ($vader->forecast->tabular->time->temper

我的xml php脚本有问题。 XML文档:


我想要一个名为:
$temp
的变量中的温度,如果您正在获取输出

echo$temp->temperature,,$temp->windSpeed,PHP_EOL

由此,您可以得到如下所示的温度值

PHP代码:

    $temp_array = array();
    $tempt_str = ''
    $i = 0;
    foreach ($vader->forecast->tabular->time->temperature as $temp) {
       $tempt_str .= 'temperature : '.$temp->temperature.''.'windSpeed : '.$temp->windSpeed.'<br/>';
       $temp_array[$i]['temperature'] = $temp->temperature;
       $temp_array[$i]['windSpeed'] = $temp->windSpeed;
    }
$temp_array=array();
$TEST_str=''
$i=0;
foreach($vader->预测->表格->时间->温度作为$temp){
$TEST_str.='温度:'.$temp->温度。'.'windSpeed:'.$temp->风速。
; $temp_数组[$i]['temperature']=$temp->temperature; $temp_数组[$i]['windSpeed']=$temp->windSpeed; }
有多个
s,因此您可以循环这些。此外,
温度
风速
也在属性中

foreach ($vader->forecast->tabular->time as $time) {
   echo $time->temperature->attributes()->value, ' ', $time->windSpeed->attributes()->mps, PHP_EOL;

   // or store temperature in a variable?
   // $temp = $time->temperature;
   // echo $temp->attributes()->value; // 14
   // echo $temp->attributes()->unit; // celcius
}
或者只访问第一个

echo $vader->forecast->tabular->time[0]->temperature->attributes()->value;
echo $vader->forecast->tabular->time[0]->windSpeed->attributes()->mps;

嗨,谢谢,我添加了天气数据,但仍然不工作。url:不,您不应该添加
weatherdata
,因为它是根节点。看看我的答案。
echo $vader->forecast->tabular->time[0]->temperature->attributes()->value;
echo $vader->forecast->tabular->time[0]->windSpeed->attributes()->mps;