-4

I have one txt file which contain many lines. I have to use those lines one by one for executing a code. that data of single line i have to save in a variable. i have to perform same action for every line.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3563010
  • 29
  • 1
  • 5
  • 1
    Use `file` function to have each line as array item, then loop through array – Anthony Jul 11 '14 at 08:24
  • actually i have access_token i have to use them for performing some action. each access_token is in new line. so i have to use one by one all access token – user3563010 Jul 11 '14 at 08:24
  • i tried file function. but i dont have much knowledge to array. so i am unable to set arry or loop for performing action. – user3563010 Jul 11 '14 at 08:25
  • $m=file_get_contents('http://example.com/a.txt'); $file=file_get_contents('https://graph.facebook.com/me/friends?access_token='.$m); – user3563010 Jul 11 '14 at 08:28
  • for each access token i have to perform task. i have many accesstoken in file a.txt . as line change access token change. – user3563010 Jul 11 '14 at 08:29

1 Answers1

1

The line end character ("\n") might need to be changed depending on the platform where the text file is generated, but this should set you on the right track:

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

$lines = explode("\n", $file);

foreach ($lines as $line) {
    ...
}

For lots of other ways see this post.

Community
  • 1
  • 1
timclutton
  • 12,682
  • 3
  • 33
  • 43