• 23-02-2014, 23:00:03
    #1
    <?php
    function Baglan($link)
    {  
    $ch  = curl_init();   
    curl_setopt($ch,CURLOPT_URL,$link);   
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);  
    curl_setopt($ch,CURLOPT_REFERER,"http://www.google.com.tr/");   
    curl_setopt($ch, CURLOPT_TIMEOUT, 9999999);   
    $Curl = curl_exec($ch);   curl_close($ch);return $Curl;
    }
    ?>
    
    <?php
    
    $il = "konya";
    
    $Site = Baglan("http://www.havadurumu.com.tr/havadurumu/".$il."");
    
    ?>
    
    <?php
    preg_match_all('@<span class="cur_temp">(.*?)</span>@si',$Site,$veri_derece);
    preg_match_all('@<span class="txt_graynote">Güncelleme:(.*?)</span>@si',$Site,$veri_guncel);
    preg_match_all('@<div class="box_silver_down w250" style="height: 80px;">
                        <div class="left pl10" style="text-align: center;">
                            <img src="/icons/(.*?)"
                               alt="(.*?)" title="(.*?)" /></div>
    @si',$Site,$veri_resim);						
    
     ?>
    <div id="blok-baslik"><h3>Konya Hava Durumu</h3></div>
    <td>Konya:
    <font size="2" face="Georgia, Times New Roman, Times, serif" style="text-shadow: 0px 1px 2px #666" color="#333333">
    <?=$veri_derece[0][0]?></td>
    <img src="http://www.havadurumu.com.tr/icons/<?=$veri_resim[1][0]?>" alt="" width="40" height="35" align="center"/>
    <font size="2" face="Georgia, Times New Roman, Times, serif" style="text-shadow: 0px 1px 2px #666" color="#333333">
    Bu Şekilde kod oluşturabildim acemilikle ama index.php ye nasıl basacam tam mantık olarak çözemedim videolu derslerden Havadurumubotu.php olarak bunu yaptım ama index.php sayfasına basmak istiyorum ne yapmam gerekli msql bağlantısı mı yoksa değişkenlerle olur mu acaba
  • 24-02-2014, 00:19:15
    #2
    Kimlik doğrulama veya yönetimden onay bekliyor.
    @Asimavi; hocam ufak bi' örnek hazırladım. bu size yardımcı olacaktır.

    fonksiyonlar.php;
    <?php
    	
    	function curl_get_contents($url)
    	{
    		if(extension_loaded("curl"))
    		{
    			$handle = curl_init();
    			
    			curl_setopt($handle, CURLOPT_URL, $url);
    			
    			curl_setopt($handle, CURLOPT_HEADER, false);
    			curl_setopt($handle, CURLOPT_NOBODY, false);
    			
    			curl_setopt($handle, CURLOPT_BINARYTRANSFER, true);
    			curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
    			
    			curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
    			curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
    			
    			curl_setopt($handle, CURLOPT_TIMEOUT, 10);
    			curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
    			
    			$response = (object) array(
    				"body" => curl_exec($handle),
    				"info" => curl_getinfo($handle),
    				"error" => (object) array(
    					"ID" => curl_errno($handle),
    					"message" => curl_error($handle)
    				)
    			);
    			
    			return $response;
    		}
    		else
    		{
    			return false;
    		}
    	}
    	
    	function get_weather_by_province($province)
    	{
    		$url = "http://www.havadurumu.com.tr/havadurumu/{$province}";
    		
    		$request = curl_get_contents($url);
    		
    		$response = $request->body;
    		
    		$name = preg_match(
    			"#\<h2>(.*?)\<\/h2\>#si",
    			$response,
    			$matches
    		) ? trim(end($matches)) : null;
    		
    		$tempature = preg_match(
    			"#\<span.*class\=\"cur\_temp\">(.*?)\<\/span\>#si",
    			$response,
    			$matches
    		) ? trim(end($matches)) : null;
    		
    		$data_update_time = preg_match(
    			"#\<span.*class\=\"txt\_graynote\".*\>(G|g)üncelleme\:(.*?)\<\/span\>#si",
    			$response,
    			$matches
    		) ? trim(end($matches)) : null;
    		
    		$weather_image = preg_match(
    			"#<div\sclass\=\"box_silver_down(.*?)>(.*?)src\=\"(.*?)\"(.*?)alt=\"(.*?)\".*class\=\"right\"#si",
    			$response,
    			$matches
    		) ? array("url" => "http://www.havadurumu.com.tr/" . trim(trim($matches[3]), "/"), "status" => $matches[5]) : null;
    		
    		return (object) array(
    			"name" => $name,
    			"province" => $province,
    			"tempature" => (object) array(
    				"deg" => $tempature,
    				"status" => $weather_image["status"]
    			),
    			"data_update_time" => $data_update_time,
    			"weather_image" => $weather_image["url"],
    		);
    	}
    index.php;
    <?php
    	# Karakter hatalarını gidermek için dosyamızı
    	# UTF-8 formatı dönüştürelim.
    	header("Content-Type: text/html; charset=UTF-8");
    	# "fonksiyonlar.php" dosyamızı dahil edelim.
    	require("fonksiyonlar.php");
    	# İl veya İlçe
    	$province = "manisa/akhisar";
    	# Hava durumu bilgisini alalım.
    	$result = get_weather_by_province($province);
    	# Sonuçları ekrana yazalım.
    ?><!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8" />
    		<title><?=$result->name;?> Hava Durumu</title>
    	</head>
    	<body>
    		<h1><?=$result->name;?> Hava Durumu</h1>
    		<h2>Güncellenme:&nbsp;<time><?=$result->data_update_time;?></time></h2>
    		<h3><img src="<?=$result->weather_image;?>" title="<?=$result->tempature->status;?>" /></h3>
    		<h4><?=$result->tempature->deg;?>&nbsp;<?=$result->tempature->status;?></h4>
    	</body>
    </html>
    Çalıştırdığımızda ise şöyle bi' sonuç bizi karşılıyor;