Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7534991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:10:31+00:00 2026-05-30T06:10:31+00:00

I want show weather information from xml to this URL: http://www.google.com/ig/api?weather=roma&hl=it using this script:

  • 0

I want show weather information from xml to this URL: http://www.google.com/ig/api?weather=roma&hl=it using this script:

<?
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=roma&hl=it');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
    <head>
        <title>Google Weather API</title>
    </head>
    <body>
        <h1><?= print $information[0]->city['data']; ?></h1>
        <h2>Today's weather</h2>
        <div class="weather">
            <img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
            <span class="condition">
            <?= $current[0]->temp_f['data'] ?>° F,
            <?= $current[0]->condition['data'] ?>
            </span>
        </div>
        <h2>Forecast</h2>
        <? foreach ($forecast_list as $forecast) : ?>
        <div class="weather">
            <img src="<?= 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
            <div><?= $forecast->day_of_week['data']; ?></div>
            <span class="condition">
                <?= $forecast->low['data'] ?>° F - <?= $forecast->high['data'] ?>° F,
                <?= $forecast->condition['data'] ?>
            </span>
        </div>
        <? endforeach ?>
    </body>
</html>

But the script does not show any output, if I delete the language specification (&hl=it) from simplexml_load_file’s parameters, it works.

Error_log_php Output:

[24-Jun-2011 11:12:53] PHP Warning:  simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: http://www.google.com/ig/api?weather=roma&amp;hl=it:1: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xE0 0x3A 0x20 0x35 in /home/site/public_html/test.php on line 2
[24-Jun-2011 11:12:53] PHP Warning:  simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: ialmente nuvoloso&quot;/&gt;&lt;temp_f data=&quot;81&quot;/&gt;&lt;temp_c data=&quot;27&quot;/&gt;&lt;humidity data=&quot;Umidit in /home/site/public_html/test.php on line 2
[24-Jun-2011 11:12:53] PHP Warning:  simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]:^ in /home/site/public_html/test.php on line 2
[24-Jun-2011 11:12:53] PHP Fatal error:  Call to a member function xpath() on a non-object in /home/site/public_html/test.php on line 3
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:10:33+00:00Added an answer on May 30, 2026 at 6:10 am

    user this code because external xml dont read from your site so use this curl code

    <?php
    /*$xml = simplexml_load_file('http://www.google.com/ig/api?weather=islamabad');
    $information = $xml->xpath("/xml_api_reply/weather/forecast_information");
    $current = $xml->xpath("/xml_api_reply/weather/current_conditions");
    $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");*/
    
    $placename = 'islamabad'; // city where you want local weather
    $place=urlencode($placename);
    $place = utf8_encode($place);
    $url = 'http://www.google.com/ig/api?weather='.$place;
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
    $raw_data = curl_exec ($ch);
    curl_close ($ch);
    
    $xml = simplexml_load_string($raw_data);
    echo $condition = $xml->weather->current_conditions->condition['data'];
    echo $temp_f = $xml->weather->current_conditions->temp_f['data'];
    echo $humidity = $xml->weather->current_conditions->humidity['data'];
    echo $icon = $xml->weather->current_conditions->icon['data'];
    echo $wind_condition = $xml->weather->current_conditions->wind_condition['data'];
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to to show the current city & weather in screen like this
I have a paragraph <p>hello<br>wor&nbsp;l&nbsp;d</p> then I want show the paragraph's html in another
this is my view for /weather: JSP FILE .... <form method=post action=/spring/krams/show/city> <select name=city>
I want show a web page (google) when i click on the button in
I have saved same image into /data/data/mypackage/img/ and now I want show this full
i want show 123 in my input tag value i write this: <INPUT TYPE=text
hii I want show a pop up Dialog box when i click on to
I want to show HTML content inside Flash. Is there some way to do
I want to show a chromeless modal window with a close button in the
I want to show the publish date in the About dialog.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.