使用水平视图在for循环中创建数组对象

时间:2010-06-23 11:17:56

标签: php arrays

 <?php
    $xml = simplexml_load_file('http://www.google.com/ig/api?weather=London');
    $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><?php print $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 round(conver_f_c($current[0]->temp_f['data'])); ?>&deg; C,
            <?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 round(conver_f_c($forecast->low['data'])); ?>&deg; C - <?php echo round(conver_f_c($forecast->high['data'])); ?>&deg; C,
                <?php echo $forecast->condition['data'] ?>
            </span>
        </div>  
        <?php endforeach ?>
    </body>
</html>

<?php
function conver_f_c($F){

    return  $C = ($F − 32) * 5/9;
}

我想要像水平这样的方式,

即使我尝试使用显示内联的UL LI,但它也失败了,

告诉我一些关于我的问题的好建议,

我想要完全像水平,期待完全像屏幕截图,

告诉我如何使用php渲染 感谢

alt text http://img163.imageshack.us/img163/7518/weatherhori.jpg

上面的片段显示出垂直,我希望o将该Verticle更改为horizo​​natal, 像这个屏幕拍摄的东西

2 个答案:

答案 0 :(得分:1)

<table>...</table>

更新

到目前为止您的最新评论:

  

我知道如何获取数组和显示   它,但我不知道要取和   以垂直方式显示   搞砸了

我觉得这将是一个愚蠢的答案,但它似乎是你不明白的......

网络基于一种称为HTML的标记语言。此语言具有标记(由尖括号分隔),允许您定义文档的结构。除此之外,您还有另一种称为CSS的语言。另一个lang允许您定义HTML将如何在屏幕上显示。

你可能会说你已经有了一个网页,你用PHP语言而不是我提到的其他两个语言来编写它。这不是真的:你用PHP编写代码,当然,你使用PHP来生成 HTML。最终到达浏览器的是HTML(Firefox,Explorer ......)。 PHP在Web服务器中执行,而不是在浏览器中执行。浏览器只能看到您生成的任何HTML。

总结一下:你必须忘记PHP,谷歌和整个天气。首先需要编写静态HTML文档并使用CSS设置样式。完成后,您最终可以使用PHP变量中的值替换动态信息的各个部分。

由于您似乎需要一个表来显示表格数据,因此相应的HTML标记为<table>

<table>
    <tr>
        <th>Web</th>
        <th>Thu</th>
        <th>Fri</th>
        <th>Sat</th>
    </tr>
    <tr>
        <td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
        <td><img src="/path/to/pics/sunny.png" width="25" height="25" alt="Sunny"></td>
        <td><img src="/path/to/pics/rainy.png" width="25" height="25" alt="Rainy"></td>
        <td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
    </tr>
    <tr>
        <td>26ºC</td>
        <td>26ºC</td>
        <td>22ºC</td>
        <td>25ºC</td>
    </tr>
<table>

我建议你找一些关于基本HTML和CSS的教程。他们将是非常宝贵的帮助。

答案 1 :(得分:0)

这就是Google所做的:

http://jsfiddle.net/bW8NA/1

相关问题