【发布时间】:2011-07-30 22:23:45
【问题描述】:
我在使用 google 天气 api 时遇到问题我一直在使用这个脚本 http://komunitasweb.com/2009/09/showing-the-weather-with-php-and-google-weather-api/ 一段时间,但之前我收到了这个错误:
警告:simplexml_load_file() [function.simplexml-加载文件]: //www.google.com/ig/api?weather=bermuda:2: 解析器错误:开始和结束标签 不匹配:元行 1 和 HEAD 在 /home/webmx04/public_html/weather/widgetlive1.php 在第 3 行
警告:simplexml_load_file() [function.simplexml-加载文件]: 302 搬家了 在 /home/webmx04/public_html/weather/widgetlive1.php 在第 3 行
警告:simplexml_load_file() [function.simplexml-load-file]: ^ in /home/webmx04/public_html/weather/widgetlive1.php 在第 3 行
警告:simplexml_load_file() [function.simplexml-加载文件]: //www.google.com/ig/api?weather=bermuda:6: 解析器错误:开始和结束标签 不匹配:HEAD 行 1 和 HTML 中 /home/webmx04/public_html/weather/widgetlive1.php 在第 3 行
警告:simplexml_load_file() [function.simplexml-加载文件]: 在 /home/webmx04/public_html/weather/widgetlive1.php 在第 3 行
警告:simplexml_load_file() [function.simplexml-load-file]: ^ in /home/webmx04/public_html/weather/widgetlive1.php 在第 3 行
警告:simplexml_load_file() [function.simplexml-加载文件]: //www.google.com/ig/api?weather=bermuda:7: 解析器错误:数据过早结束 在标记 HTML 第 1 行中 /home/webmx04/public_html/weather/widgetlive1.php 在第 3 行
警告:simplexml_load_file() [function.simplexml-load-file]:在 /home/webmx04/public_html/weather/widgetlive1.php 在第 3 行
警告:simplexml_load_file() [function.simplexml-load-file]: ^ in /home/webmx04/public_html/weather/widgetlive1.php 在第 3 行
致命错误:调用成员函数 xpath() 在非对象上 /home/webmx04/public_html/weather/widgetlive1.php 在第 4 行
谁能帮帮我,谢谢
我的代码:
<?
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=bermuda');
$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>
<div id="widget-wrapper"><!-- start widget-wrapper-->
<div class="weather"><!-- start weather-->
<h2><a href="/section/weather" title="More on Weather" target="_top">Current Weather</a></h2>
<a href="/section/weather" target="_top"><img src="<?= 'http://www.rgbdahosting.com' . $current[0]->icon['data']?>" alt="More on Weather"?></a>
<span class="condition">
<a href="/section/weather" title="More on Weather" target="_top"><H4><?= $current[0]->temp_f['data'] ?>°F</H4>
<p><?= $current[0]->condition['data'] ?></p></a>
</span>
</div><!-- end weather-->
</div> <!-- end widget-wrapper-->
</body>
【问题讨论】:
-
看到你标记的来源不匹配意味着标记没有关闭或在不正确的地方关闭
-
您好,谢谢您的回复,但是我在上面的代码中添加的不匹配是什么意思,您能看到我做错了什么吗,我只是不知道 komunitasweb.com/2009/09/… 中的演示有什么问题工作正常,但是当我将其复制粘贴到我的主机中时,它只会给我错误
-
由于某种原因它自己修复了我对发生的事情一无所知
-
现在又坏了不知道是什么原因造成的这个问题
标签: php weather-api google-weather-api