私はyiiフレームワークで作業しています。カールエクステンションを使用しています。私はmain.phpにコードを含めました-
'curl'=>array(
'class' => 'application.extensions.curl.Curl',
),
また、protected/extensions の下に curl.php ファイルを含めました。コントローラーには、コードとして=が含まれていました
public function actionGetWeather()
{
$place='pune';
$data = Yii::app()->curl->run('http://www.google.com/ig/api?weather='.$place.'&hl=en');
$xml = new SimplexmlElement($data);
foreach($xml->weather as $item) {
foreach($item->current_conditions as $new) {
//For temperature in fahrenheit replace temp_c by temp_f
$current_temperature=$new->temp_c['data'];
$current_humidity=$new->humidity['data'];
}
$current_condition=$item->forecast_conditions[0]->condition['data'];
$next_temperature=$item->forecast_conditions[1]->high['data'];
//to convert Fahrenheit into Celcius
$next_temperature=round(($next_temperature-32)*(5/9));
$next_condition=$item->forecast_conditions[1]->condition['data'];
}
echo " Current temperature :".$current_temperature."<br />";
echo "Current condition : ".$current_condition."<br />";
echo $current_humidity;
echo "Tomorrows temperature :".$next_temperature."<br />";
echo "Tomorrows condition : ".$next_condition."<br />";
}
しかし、行 "$xml = new SimplexmlElement($data);" で文字列を XML として解析できなかったため、エラーが発生しました。では、どのような変更を加える必要がありますか? 私を助けてください