반응형
간단한 예제 입니다.
웹에서 검색하여 짜집기 한 소스입니다.


<?php

$xml_data= @file_get_contents("http://www.google.com/ig/api?hl=ko&weather=seoul"); 
$xml_data = iconv("EUC-KR","UTF-8", $xml_data); 
$xml = simplexml_load_string($xml_data); 
$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");
?>

<head>
    <title>Google Weather API</title>
</head>
<html> 
<body>
    <h1><?php echo $information[0]->city['data']; ?></h1>
    <h2>Today's weather</h2>
    <div class="weather">
        <img src="<?php echo 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
        <span class="condition">
        <?php echo $current[0]->temp_f['data'] ?>&deg; F,
        <?php echo $current[0]->condition['data'] ?>
        </span>
    </div>
    <h2>Forecast</h2>
    <?php foreach ($forecast_list as $forecast) : ?>
    <div class="weather">
        <img src="<?php echo 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
        <div><?php echo $forecast->day_of_week['data']; ?></div>
        <span class="condition">
            <?php echo $forecast->low['data'] ?>&deg; F - <?php echo $forecast->high['data'] ?>&deg; F,
            <?php echo $forecast->condition['data'] ?>
        </span>
    </div>
    <?php endforeach ?>
</body>
</html> 

반응형

+ Recent posts