I am working in yii framework. I am using curl extension. i had included code in main.php as-
'curl'=>array(
'class' => 'application.extensions.curl.Curl',
),
And included curl.php file under protected/extensions. In controller i had included code as=
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 />";
}
But its giving an error as String could not be parsed as XML at line "$xml = new SimplexmlElement($data);" So what changes i need to make? please help me
$data
is or is not XML. (When I dereferenced the URI you're using, the error response I got was not XML.) – C. M. Sperberg-McQueen Dec 21 '12 at 17:05