• 03-02-2015, 10:52:11
    #1
    Merhaba arkadaşlar file_get_contents ile veri çekiyorum. Ancak bir yerde takıldım. Örneğin
    http://localhost.com/$region1/hava_durumu
    http://localhost.com/$region2/hava_durumu
    http://localhost.com/$region3/hava_durumu
    nasıl bir kodla verileri tek tek uğraşmadan bir değişkende çıktı aldırırım.

    Örneğin: http://localhost.com/$region1/ çekince $degree = 23
    http://localhost.com/$region2/ çekince $degree = 36


    bir örnek vermezseniz hepsine ayrı ayrı file_get_contents komutu kullanıcam.bilmiyorum anlatabildim mi ama sorun bu teşekkürler.
  • 03-02-2015, 10:57:58
    #2
    Üyeliği durduruldu
    tam anlamadımda döngü kurmayı denermisin ? bir den fazla file_get_contents kullanmazsın veya bir fonksiyon oluştur fonksiyon üzeri işlem yap veya her veri 1 kaynaktan geliyorsa o kaynağı çek üzerinde regex ile istediğin kısımları al sonra istediğin yerlere göndert
  • 03-02-2015, 11:07:02
    #3
    ismailbayhan adlı üyeden alıntı: mesajı görüntüle
    tam anlamadımda döngü kurmayı denermisin ? bir den fazla file_get_contents kullanmazsın veya bir fonksiyon oluştur fonksiyon üzeri işlem yap veya her veri 1 kaynaktan geliyorsa o kaynağı çek üzerinde regex ile istediğin kısımları al sonra istediğin yerlere göndert
    Hocam şu şekilde izah edeyim

    $json_url 		= "https://localhost/$reg/"; //$regden $reg10 a kadar gidiyor
    $json_data		= file_get_contents($json_url);
    $content		= json_decode($json_data);
    
    $degree		= $content->participants->degree; //ve hepsinin içinden çektiğim degree değeri farklı
    mesela ben $reg1 değeri için $reg1'in değeri kaçsa onu $degree1 değişkenine atamak istiyorum bu $reg2 $degree2 diye gitsin istiyorum. bir örnek gösterebilir misiniz cidden beynim durdu. cevabınız için teşekkürler
  • 03-02-2015, 11:23:45
    #4
    fixir adlı üyeden alıntı: mesajı görüntüle
    Hocam şu şekilde izah edeyim

    $json_url 		= "https://localhost/$reg/"; //$regden $reg10 a kadar gidiyor
    $json_data		= file_get_contents($json_url);
    $content		= json_decode($json_data);
    
    $degree		= $content->participants->degree; //ve hepsinin içinden çektiğim degree değeri farklı
    mesela ben $reg1 değeri için $reg1'in değeri kaçsa onu $degree1 değişkenine atamak istiyorum bu $reg2 $degree2 diye gitsin istiyorum. bir örnek gösterebilir misiniz cidden beynim durdu. cevabınız için teşekkürler

    <?php
    $tmpArray = array();
    for($i=0;$i<10;$++){
    	if ( $i==0 ){
    		$tmpStr = ${$reg};
    	} else {
    		$tmpStr = ${$reg. $i};
    	}
    	
    	$json_url = "https://localhost/$tmpStr/"; //$regden $reg10 a kadar gidiyor
    	$json_data = file_get_contents($json_url);
    	$content = json_decode($json_data);
    	
    	$degree = $content->participants->degree; //ve hepsinin içinden çektiğim degree değeri farklı
    	
    	$tmpArray[ $tmpStr ] = $degree;
    	
    }
    
    print_r( $tmpArray );
    ?>

    şöyle bir şey mi istiyorsunuz acaba?
  • 03-02-2015, 12:23:04
    #5
    yvolkan adlı üyeden alıntı: mesajı görüntüle
    <?php
    $tmpArray = array();
    for($i=0;$i<10;$++){
    	if ( $i==0 ){
    		$tmpStr = ${$reg};
    	} else {
    		$tmpStr = ${$reg. $i};
    	}
    	
    	$json_url = "https://localhost/$tmpStr/"; //$regden $reg10 a kadar gidiyor
    	$json_data = file_get_contents($json_url);
    	$content = json_decode($json_data);
    	
    	$degree = $content->participants->degree; //ve hepsinin içinden çektiğim degree değeri farklı
    	
    	$tmpArray[ $tmpStr ] = $degree;
    	
    }
    
    print_r( $tmpArray );
    ?>

    şöyle bir şey mi istiyorsunuz acaba?
    hocam hemen hemem boyle ancak degree2 yi nasil alirim $tmpArray[0] şeklinde mi?
  • 03-02-2015, 12:27:04
    #6
    fixir adlı üyeden alıntı: mesajı görüntüle
    hocam hemen hemem boyle ancak degree2 yi nasil alirim $tmpArray[0] şeklinde mi?
    $tmpArray[ $tmpStr ] = $degree;

    yukarıdaki kısmı

    $tmpArray[ $i ] = $degree; olarak değiştirsen

    degree2 'yi

    echo $tmpArray[ 1 ]; olarak alabilirsin.

    Dizi sıfırdan başladığı için 2 değeri 1de olacaktır
  • 03-02-2015, 15:26:54
    #7
    yvolkan adlı üyeden alıntı: mesajı görüntüle
    $tmpArray[ $tmpStr ] = $degree;

    yukarıdaki kısmı

    $tmpArray[ $i ] = $degree; olarak değiştirsen

    degree2 'yi

    echo $tmpArray[ 1 ]; olarak alabilirsin.

    Dizi sıfırdan başladığı için 2 değeri 1de olacaktır
    $id1			= $content->participants[0]->summonerId;
    if(empty($id1)) header("Location:../404.html"); 
    $id2			= $content->participants[1]->summonerId;
    $id3		= $content->participants[2]->summonerId;
    $id4		= $content->participants[3]->summonerId;
    $id5		= $content->participants[4]->summonerId;
    $id6			= $content->participants[5]->summonerId;
    $id7		= $content->participants[6]->summonerId;
    $id8		= $content->participants[7]->summonerId;
    $id9		= $content->participants[8]->summonerId;
    $id10			= $content->participants[9]->summonerId;
    
    $tmpArray = array();
    for($i=0;$i<10;$i++){
    if ( $i==0 ){
    $tmpStr = ${$id};
    } else {
    $tmpStr = ${$id. $i};
    }
       
    $json_urlx 		= "https://localhost/by-summoner/$tmpStr/entry?api_key=7cc4162d-46a5-41ed-bd8f-783a18fc1c87";
    $json_datax		= file_get_contents($json_urlx);
    $contentx		= json_decode($json_datax, true);
    $db1 			= $contentx[$tmpStr]; 
    $db1 			= $db1[0]; 
    $tier			= $db1['tier']; 
    
        
    $tmpArray[$i] = $tier;
    
        //$tmpStr boş geliyor hocam
    }
    hocam sabrınız için ayrıca teşekkürler
  • 03-02-2015, 15:33:46
    #8
    fixir adlı üyeden alıntı: mesajı görüntüle
    $id1			= $content->participants[0]->summonerId;
    if(empty($id1)) header("Location:../404.html"); 
    $id2			= $content->participants[1]->summonerId;
    $id3		= $content->participants[2]->summonerId;
    $id4		= $content->participants[3]->summonerId;
    $id5		= $content->participants[4]->summonerId;
    $id6			= $content->participants[5]->summonerId;
    $id7		= $content->participants[6]->summonerId;
    $id8		= $content->participants[7]->summonerId;
    $id9		= $content->participants[8]->summonerId;
    $id10			= $content->participants[9]->summonerId;
    
    $tmpArray = array();
    for($i=0;$i<10;$i++){
    if ( $i==0 ){
    $tmpStr = ${$id};
    } else {
    $tmpStr = ${$id. $i};
    }
       
    $json_urlx 		= "https://localhost/by-summoner/$tmpStr/entry?api_key=7cc4162d-46a5-41ed-bd8f-783a18fc1c87";
    $json_datax		= file_get_contents($json_urlx);
    $contentx		= json_decode($json_datax, true);
    $db1 			= $contentx[$tmpStr]; 
    $db1 			= $db1[0]; 
    $tier			= $db1['tier']; 
    
        
    $tmpArray[$i] = $tier;
    
        //$tmpStr boş geliyor hocam
    }
    hocam sabrınız için ayrıca teşekkürler


    <?php
    $id1            = $content->participants[0]->summonerId; 
    if(empty($id1)) header("Location:../404.html");  
    $id2            = $content->participants[1]->summonerId; 
    $id3        = $content->participants[2]->summonerId; 
    $id4        = $content->participants[3]->summonerId; 
    $id5        = $content->participants[4]->summonerId; 
    $id6            = $content->participants[5]->summonerId; 
    $id7        = $content->participants[6]->summonerId; 
    $id8        = $content->participants[7]->summonerId; 
    $id9        = $content->participants[8]->summonerId; 
    $id10            = $content->participants[9]->summonerId; 
    
    $tmpArray = array(); 
    for($i=1;$i<=10;$i++){
    	$tmpStr = ${'id'.$i}; 
        
    	$json_urlx       = "https://localhost/by-summoner/$tmpStr/entry?api_key=7cc4162d-46a5-41ed-bd8f-783a18fc1c87"; 
    	$json_datax      = file_get_contents($json_urlx); 
    	$contentx        = json_decode($json_datax, true); 
    	$db1             = $contentx[$tmpStr];  
    	$db1             = $db1[0];  
    	$tier            = $db1['tier'];  
    	
    	$tmpArray[$i] = $tier;
    } 
    
    
    print_r( $tmpArray );

    Kodları görünce tabi işlem değişebiliyor. Ekran çıktısı nasıl geliyor acaba?
  • 03-02-2015, 16:05:42
    #9
    yvolkan adlı üyeden alıntı: mesajı görüntüle
    <?php
    $id1            = $content->participants[0]->summonerId; 
    if(empty($id1)) header("Location:../404.html");  
    $id2            = $content->participants[1]->summonerId; 
    $id3        = $content->participants[2]->summonerId; 
    $id4        = $content->participants[3]->summonerId; 
    $id5        = $content->participants[4]->summonerId; 
    $id6            = $content->participants[5]->summonerId; 
    $id7        = $content->participants[6]->summonerId; 
    $id8        = $content->participants[7]->summonerId; 
    $id9        = $content->participants[8]->summonerId; 
    $id10            = $content->participants[9]->summonerId; 
    
    $tmpArray = array(); 
    for($i=1;$i<=10;$i++){
    	$tmpStr = ${'id'.$i}; 
        
    	$json_urlx       = "https://localhost/by-summoner/$tmpStr/entry?api_key=7cc4162d-46a5-41ed-bd8f-783a18fc1c87"; 
    	$json_datax      = file_get_contents($json_urlx); 
    	$contentx        = json_decode($json_datax, true); 
    	$db1             = $contentx[$tmpStr];  
    	$db1             = $db1[0];  
    	$tier            = $db1['tier'];  
    	
    	$tmpArray[$i] = $tier;
    } 
    
    
    print_r( $tmpArray );

    Kodları görünce tabi işlem değişebiliyor. Ekran çıktısı nasıl geliyor acaba?
    Hocam +r10 çok sağolun bi sorum daha olacak eğer herhangi bi $tier değeri boş ise sadece boş olan $tiere bir değer atayabilir miyim
    print_r sonucu Array ( [1] => GOLD [2] => GOLD [3] => GOLD [4] => [5] => GOLD [6] => PLATINUM [7] => GOLD [8] => PLATINUM [9] => [10] => burdaki boş alanları Bos diye yazdırıcam ve [1] [2] kaldırmak istiyorum
    if(empty($db1)){$tmpArray ="Bos";}	//bunu denedim hepsi Bos oldu