I have a txt file (links.txt) There are thousands of links in it
I want to sort all the links using the following code
<?php
function get_domain($url)
{
$pieces = parse_url($url);
$domain = isset($pieces['host']) ? $pieces['host'] : $pieces['path'];
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
return $regs['domain'];
}
return false;
}
print get_domain("http://mail.somedomain.co.uk"); // outputs 'somedomain.co.uk'
?>
How to call file 1 and arrange them and save them again?
Update
In my file (domains.txt) there are about 10,000 domains I want to filter domains with the above code
for example:
Before:
http://www.example.com/about
www.example.net/index.php
http://subdomain.example.org/
http://www.example.co/page-1
http://www.example.co.uk
After:
example.com
example.net
example.org
example.co
example.co.uk