您好
看了這個教學 http://blog.davidou.org/archives/704
進行操作但是出現錯誤訊息:
Warning: preg_match_all(): Unknown modifier '(' in /var/www/html/accuweather.php on line 17
Warning: preg_match_all(): Unknown modifier '(' in /var/www/html/accuweather.php on line 18
Warning: preg_match_all(): Unknown modifier '(' in /var/www/html/accuweather.php on line 19
Warning: preg_match_all(): Unknown modifier '?' in /var/www/html/accuweather.php on line 20
Warning: preg_match_all(): Unknown modifier '?' in /var/www/html/accuweather.php on line 21
請問如何修正?!
<?php
function getTextBetweenTags( $string, $tagname ) {
preg_match( "/\<{$tagname}\>(.*)\<\/{$tagname}\>/", $string, $matches );
return $matches[1];
}
$contents = file_get_contents("http://realtek.accu-weather.com/widget/realtek/weather-data.asp?location=cityId:315040");
var_dump( getTextBetweenTags( $contents, 'temperature' ) );
?>
應該你看的懂 ..... 自己改吧 ....
哈我抓到 ......
string(2) "86"
你還要改 ... 應該是 86°F ==> 30°C
想請教您
我可以抓出weathericon的值
var_dump( getTextBetweenTags( $contents, 'weathericon' ) );
應該如何搭配天氣編號顯示圖示
https://developer.accuweather.com/weather-icons
我抓到
string(2) "07"
那圖是
https://developer.accuweather.com/sites/default/files/07-s.png
就用字串 07 就可以了吧 ?
php 字串相加 .... 就有 07-s.png 圖了 ....
是的
請問您實際的做法是?
隨便寫一下 .....
建議還是用 MVC 架構
<html>
<title>抓天氣</title>
<style type="text/css">
<!--
body {
color:#3233EF;
margin: 0px;
}
-->
</style>
<html>
<body width="717" height="186"><font size="4">
<?php
function getTextBetweenTags( $string, $tagname ) {
preg_match( "/\<{$tagname}\>(.*)\<\/{$tagname}\>/", $string, $matches );
return $matches[1];
}
$contents = file_get_contents("http://realtek.accu-weather.com/widget/realtek/weather-data.asp?location=cityId:315040");
$pic = getTextBetweenTags( $contents, 'weathericon' ) ;
$out_pic = "https://developer.accuweather.com/sites/default/files/".$pic."-s.png";
?>
<img src="<?php echo $out_pic ?>">
</font>
</body>
</html>
敢問什麼是MVC 架構