Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

split links in text file PHP

Tags:

php

I have a text file which contains many (over 5000) links. Like this:

http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh
http://www.website.com/rgfdefvrggh

etc etc....

I'm trying to fetch each link at a time and do stuff with it....

so one by one, get the link do something and then move on to the next....

I don't know how i would split the links up...

they're all in a .txt file, separated by a line break.

any ideas?


1 Answers

Use the file function to read your file in an array, one element per line. For example:

$links = file('data.txt');
foreach($link in $links) {
    // do something with $link
}
like image 92
Jon Avatar answered Apr 18 '26 08:04

Jon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!