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?
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
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)?
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!
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:
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