1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Passing values for Array through PHP Variable

Discussion in 'PHP' started by roopajyothi, Jan 21, 2012.

  1. #1
    I am trying to pass values for Array through PHP but i cant get to make work!
    Some one please help
    here is the code i tried

    <?php
    $masterkeylist11 = file_get_contents('http://domain.com.com/full/forbidden/finalkeys.txt');
    $myvar = array($masterkeylist11);
    echo $myvar[3];
    ?>
    
    PHP:
    The in file contents of finalkeys.txt
    
    googlecom,yahoocom,bingcom,rediffcom,ebaycom,googleus,googleca,
    
    PHP:
    Some one please tell me whats the error here
     
    Last edited: Jan 21, 2012
    roopajyothi, Jan 21, 2012 IP
  2. yho_o

    yho_o Well-Known Member

    Messages:
    353
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    #2
    text.txt contents:


    text1,text2,text3,text4
    Code (markup):
    
    <?php
        $masterkeylist11 = file_get_contents('text.txt'); // all text inside the file seperated by comma
        $value = explode(',', $masterkeylist11);  // explode the comma and put each text in the array($values) as an element
        echo $values[0] . "<br />"; // First text
        echo $values[1] . "<br />"; // Second text
        echo $values[2] . "<br />"; // Third text
        echo $values[3] . "<br />"; // Fourth text
    ?>
    
    Code (markup):
    hope it helps, Thanks
     
    yho_o, Jan 21, 2012 IP
  3. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #3
    A small modification to the code above:

    finalkeys.txt
    googlecom,yahoocom,bingcom,rediffcom,ebaycom,googleus,googleca,
    Code (markup):
    <?php
        $masterkeylist11 = file_get_contents('/full/forbidden/finalkeys.txt');
        $eachValue = explode(',', $masterkeylist11); 
        $length = count($eachValue);
    
    for ($i=0; $i<$length; $i++){
    echo $eachValue[$i].'<br/>';
    }
    ?>
    PHP:

    You can try that. Also, the path to your text file, must be relative to the PHP file in which it is being called. I may be wrong but I don't think you can access it through the domain name like you had in your example.
     
    Andre91, Jan 21, 2012 IP
  4. yho_o

    yho_o Well-Known Member

    Messages:
    353
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    #4
    i was going to do a loop too ^^, but i noticed that he is trying to echo specific value not all

    otherwise thanks for the modification :)

    Cheers
     
    yho_o, Jan 21, 2012 IP