0

Im looking to do something like the following

$file = ('file.txt');
$fopen($file);

then read each line from the file individually and set it as a specific array

like so

read $file get $line1 set as $array[0]
read $file get $line2 set as $array[1]
read $file get $line3 set as $array[2]

I would like to use these arrays created from the lines on the text file IN PLAIN TEXT like this:

$urlout = file_get_contents("http://myurl.com/?=$line1");
echo $urlout;
$urlout2 = file_get_contents("http://myurl.com/?=$line2");
echo $urlout2;
$urlout3 = file_get_contents("http://myurl.com/?=$line3");
echo $urlout3;

So if the array were 123.22.11.22 the link would look like this:

$line1 = array[0] (123.22.11.22)
$urlout = file_get_contents("http://myurl.com/?=$line1");
echo $urlout;

and the result would be

Info for 123.22.11.22 more info some more

3
  • 1
    I am not getting what error you are seeing or where you stucked up .. Commented Jul 17, 2015 at 7:04
  • Basically what im trying to accomplish is pulling each line of text and outputting that line to a file_get_contents value and then return the result Commented Jul 17, 2015 at 7:27
  • Your logic explained above is right. You are almost there to answer. Check my answer. Commented Jul 17, 2015 at 7:30

3 Answers 3

3

Modified answer as per the change indicated by the user :

Reading 2 lines on each loop..

$lines = file("file.txt");
for($i=0 ; $i<count($lines); $i=($i+2) )
{
    echo file_get_contents("http://myurl.com/?=".$lines[$i]);
    echo file_get_contents("http://myurl.com/?=".$lines[($i + 1)]);
}

Imp Note : A URL can be used as a filename with file_get_contents() function, only if the fopen wrappers have been enabled.

Sign up to request clarification or add additional context in comments.

5 Comments

That still for some reason is only outputting the first line :( Basically there are 2 IP's in a text file and i want to read from the file and set the IP on the first line to $line1 and set the second to $line2 so on and so forth
I have a syntax error in echo file_get_contents("myurl.com/?=$lines[($i + 1)]");
Try now. $lines[] should not be in quotes
Hmm still having issues, maybe you can check what im doing wrong? pastebin.com/Z0Nbp2a9 The output can be seen shut-em-down.com/Soap/skyperesolver.php as of current type in parra1995 and hit resolve.
Where it says "Invalid IP address or Domain" should be showing the geo info for the first IP address :/
0
$handle = fopen("file.txt", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        echo file_get_contents("http://myurl.com/?=$line");
    }

    fclose($handle);
}

Comments

0

The answer was to insert a "\n" separator upon inserting into the text file, then removing it after the first result was called

$lines = file("geo.txt");
for($i=0 ; $i<count($lines); $i=($i+2) )
{
echo file_get_contents("https://test.com/api/GEO.php?info=".$lines[$i]);

$lolz = file_get_contents("https://test.com/api/GEO.php?info=".$lines[($i + 1)]);
$lolz = str_replace(" \n", '', $lolz);
echo "<br>".$lolz;

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.