phpzend-frameworkzend-filterzend-filter-strip-tags

ZendFramework - How to get all the list of TLD to remove from website?


I have a long list with website address's. But i have to filter them and get only the part "abcd". In my cut/paste/algorithm i have very random format's of websites to deal, and dealing with large list is like very time consuming.

Example:

www.abcd.tld.tld.tld to abcd
http://www.abcd.tld.tdl to abcd
abcd.tld to abcd
abcd.tld.tld to abcd
http://abcd.tld to abcd
http://abcd.tld.tld to abcd

Which Zend_Filter i can ues tot cut front and tail, and always get the middle part of "abcd". Or is there any PHP built-in function which can do this?


Solution

  • You could do this with some basic string functions in PHP. Load all your URLs into a string variable and then do a simple str_replace

    $old_urls; // load your urls into this variable
    $search = array('http://','https://','www.','.com','.net','.us','.org','.edu','.us'); // etc, add more tlds
    $new_urls = str_replace($search,'',$old_urls);
    

    Would this work for you?