Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
    
First, check to see whether the data in the variable $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

1 Answer 1

Probably Google Weather Api has been closed. Try http://worldweatheronline.com/ weather api, it's almost same.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.