Words on txt file

Discussion in 'PHP' started by roice, Mar 27, 2010.

  1. #1
    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?
     
    roice, Mar 27, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi, better should be using file(). Than every element will be array element and you can use array functions (such as array_unique() etc...)
    Regards :)
     
    koko5, Mar 28, 2010 IP
  3. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks!
    so, what exactly is the different between FILE and FILE_GET_CONTENT?
    Is it the way the content organized (records in array or full content in variable)?
     
    roice, Mar 28, 2010 IP
  4. ThomasTwen

    ThomasTwen Peon

    Messages:
    113
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, thats exactly it. file() will give you an array, so that $var[0] is the first line of the file, $var[1] the second line and so on. Then, you just have to ignore the first few lines that don't contain domains, and you are done!
     
    ThomasTwen, Mar 28, 2010 IP
  5. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #5
    file_get_contents returns all data as a single string, but file returns array, which can be converted as string using function implode. There are a lot of powerful array functions, that can be used here,example:

    function mydomainfilter($s){
    return (trim($s)!='')&preg_match('#^[\w\-]+(\.\w+)+$#miu',trim($s));
    }
    
    echo implode('',array_filter(file('http://www.wsmdomains.com/ExpiredDomains/30mar2010.txt'),'mydomainfilter'))."\n";
    
    PHP:
     
    koko5, Mar 28, 2010 IP
  6. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank you both

    koko - what does your code doing?
     
    roice, Mar 31, 2010 IP
  7. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #7
    It takes text file as array and removes duplicates,empty,carriage return,return or spaces only elements and those which doesn't match regular expression for domain checking (you can improve the regexp): all done via php array functions.
    Regards :)
     
    koko5, Mar 31, 2010 IP
  8. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    OK, Thanks
     
    roice, Apr 1, 2010 IP