• 30-11-2009, 04:03:40
    #1
    arkadaşlar aşağıdaki kod text dosyasından veri çekme kodu peki ben bu textlere 1.2.3.4.5........ seklınde ad verip nasıl rastgele veri çekebilirim ?


       <?php
    $handle = @fopen("text_alani.txt", "r");
    if ($handle) {
        while (!feof($handle)) {
            $buffer = fgets($handle, 4096);
            echo $buffer;
        }
        fclose($handle);
    }
    ?>
  • 30-11-2009, 04:37:08
    #2
    Üyeliği durduruldu
    <?php 
    $dosyalar = array(
        '1.txt',
        '2.txt',
        '3.txt',
        '4.txt',
        '5.txt'
    );
    $handle = @fopen($dosyalar[array_rand($dosyalar)], "r"); 
    if ($handle) { 
        while (!feof($handle)) { 
            $buffer = fgets($handle, 4096); 
            echo $buffer; 
        } 
        fclose($handle); 
    } 
    ?>
  • 30-11-2009, 04:53:16
    #3
    Eline sağlık hocam bende yazdım tam denıyordum cevap verdiniz saolun...
    buda benımkı çalıştı bizzat

    		  <?php
    $toplam = "10";
    $dosya_uzantisi = ".txt";
    $dosya = "t";
    
    
    
    
    
    $rastgele = mt_rand($ilk, $toplam);
    
    $dosya_adi = $rastgele . $dosya_uzantisi;
    
    $handle = @fopen("$dosya/$dosya_adi", "r");
    
    if ($handle) {
        while (!feof($handle)) {
            $buffer = fgets($handle, 4096);
            echo $buffer;
        }
        fclose($handle);
    }
    
     ?>
  • 30-11-2009, 05:01:37
    #4
    Üyeliği durduruldu
    rica ederim, ayrıca yazdıgınız kodlar ile aynı işi yapacak kısa hali;

    echo file_get_contents(rand(1, 10) . '.txt');