Page 1 of 1

Words on txt file

Posted: Sun Mar 28, 2010 1:52 am
by roice
Hello everyone,
I want to put every domain, from this list:
http://www.wsmdomains.com/ExpiredDomains/30mar2010.txt
and putting it into variable.
For that I'm using the PHP code "$string = file_get_contents(http://www.wsmdomains.com/ExpiredDomains/30mar2010.txt);"

what is the code that cut every domain and put it into varialbe?

Re: Words on txt file

Posted: Sun Mar 28, 2010 11:26 am
by ridgerunner
This script should do the trick for you:

Code: Select all

<?php 
$string = file_get_contents('http://www.wsmdomains.com/ExpiredDomains/30mar2010.txt');
$re = '%^                                           # regex to match a valid DNS domain
    (?!.{256})                                      # URL total length must be less than 256 chars
    (?:                                             # non-capture group for alternation and quantifier
      [0-9A-Za-z]\.                                 # each label part can be a single ALPHANUM or
      |                                             # up to 63 ALPHANUM with dashes, but must not
      [0-9A-Za-z][-0-9A-Za-z]{0,61}[0-9A-Za-z]\.    # begin or end with a dash, each followed by a dot.
    )*                                              # any number of parts can precede TLD
    (?:                                             # group for top level domain (TLD) alternatives
      com|edu|gov|int|mil|net|org|biz               # these are the recognized top level domains
      |info|name|pro|aero|coop|museum               # as defined by the regulating organizations see:
      |arpa|asia|cat|jobs|mobi|tel|travel           # http://data.iana.org/TLD/tlds-alpha-by-domain.txt
      |[a-za-z]{2}                                  # generic two ALPHA country TLDS
    )                                               # end non-capture group of required TLD
    $%ixm';
$count = preg_match_all($re, $string, $matches, PREG_SET_ORDER);
if ($count) {
    echo($count . " matches found.\n");
    for ($i = 0; $i < $count; $i++) {
        echo(
            sprintf("Domain #%d = \"%s\"\n", $i + 1, $matches[$i][0])
        );
    }
}
else {
    echo("\nNo matches found.\n");
}
?>
BTW - This script contains a really good regex for validating DNS hosts.
:)

Re: Words on txt file

Posted: Mon Mar 29, 2010 10:54 am
by AbraCadaver
That is nice, however if the file is always like that I would use file() and throw away the first 4 lines:

Code: Select all

$lines = file("http://www.wsmdomains.com/ExpiredDomains/30mar2010.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

Re: Words on txt file

Posted: Wed Mar 31, 2010 2:39 am
by roice
ridgerunner - Damn, you are good...:)
AbraCadaver - thanks you too.

I think I'm gonna need these both codes...

Thanks!