Skip to content

Instantly share code, notes, and snippets.

@vivithemage
Created October 20, 2018 20:54
Show Gist options
  • Save vivithemage/aaea83c365bd8761791c43c53a3a8cd7 to your computer and use it in GitHub Desktop.
Save vivithemage/aaea83c365bd8761791c43c53a3a8cd7 to your computer and use it in GitHub Desktop.
<?php
$filename = 'master_no_duplicates.csv';
$contents = file($filename);
function get_domain($url)
{
$pieces = parse_url($url);
$domain = isset($pieces['host']) ? $pieces['host'] : '';
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;
}
echo "starting";
foreach($contents as $line) {
echo "adding: ".$line;
$line_to_write = get_domain($line) . ",";
file_put_contents("results.txt", $line_to_write, FILE_APPEND);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment