#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    410
    Rep Power
    8

    Question Regex To Grab Domain


    Folks,

    I need a regex to extract the domain name from any url. No matter what the url looks like. Whether it has more than one dot (2nd level, 3rd level, 4th level, 5th level, etc. level domain) and whether or not it has the http://, https://, www., etc.).
    In short, it must work on any url in the world. No matter what format the url is in aslong as the url is a valid one. No matter how good, ugly, short or long the url is.
    I am spoiled for choice as too many samples are provided here and I don't know which one will best suit my purpose:
    https://stackoverflow.com/questions/...-name-from-url

    Which one is your best pick for my purpose and why that one over the others ?
    Last edited by UniqueIdeaMan; October 17th, 2017 at 05:37 PM.
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,344
    Rep Power
    2063
    Regex? *shudders*

    No need.

    Again... The PHP manual is your friend. You really need to learn how to use it.

    PHP: parse_url - Manual
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    410
    Rep Power
    8
    Originally Posted by Catacaustic
    Regex? *shudders*

    No need.

    Again... The PHP manual is your friend. You really need to learn how to use it.

    PHP: parse_url - Manual

    Would you use the parse_url over all the regex codes mentioned here:
    https://stackoverflow.com/questions/...-name-from-url
    If parse_url is fine then why did those programmers in that above mentioned link bother with regex ?

    Is my parse_url code ok ?

    PHP Code:
        <?php

        
    include 'config.php';

        
    $url "http://one.com/1.php";
        
    $domain parse_url($urlPHP_URL_HOST);
        echo 
    $domain;

        
    $url "http://two.com/2.htm";
        
    $domain parse_url($urlPHP_URL_HOST);
        echo 
    $domain;


        
    $domain parse_url("http://three.com/3.html"PHP_URL_HOST);
        echo 
    $domain;


        
    $domain parse_url("http://four.com/4.shtm"PHP_URL_HOST);
        echo 
    $domain;


        
    $domain parse_url('http://five.com/5.shtml'PHP_URL_HOST);
        echo 
    $domain;

        
    $domain parse_url('http://usr:pss@example.com:81/mypath/myfile.html?
        a=b&b[]=2&b[]=3#myfragment'
    PHP_URL_HOST);
        echo 
    $domain;

        
    ?>
    Notice how many types of urls I tested with parse_url. Parse_url seems to manage to grab the 2nd level domain as I want.
  6. #4
  7. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,344
    Rep Power
    2063
    Originally Posted by UniqueIdeaMan
    Would you use the parse_url over all the regex codes mentioned here:
    Yes. The majority of those regex codes are terrible, and would need modifications to make them work in the "real world". parse_url() just works on everything.

    Originally Posted by UniqueIdeaMan
    If parse_url is fine then why did those programmers in that above mentioned link bother with regex ?
    You'd have to ask them, but most likely they didn't know about it, or they just like to use tools they know even if they aren't the best tool for that job.

    Originally Posted by UniqueIdeaMan
    Notice how many types of urls I tested with parse_url. Parse_url seems to manage to grab the 2nd level domain as I want.
    Good, so it's the right tool for the job.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Location
    Lakewood, WA
    Posts
    230
    Rep Power
    18
    I'm sorry, but have you not heard of this new thing called Google? Serious question: Ever used it?

    The reason I asked is that while I don't know for sure because it wouldn't be my method of choice, I do indeed suspect that it can be done with regex - since everything can be done with regex - and the first thing I would do would be to "Google" it.

    To "Google" is a verb. Basically, you navigate to https://www.Google.com, enter your question into the little box, and than clicky the "Google Search" button.

    Here's a picture => google.png No, you awful people, it is not Goatse...

    Amazing things happen! As if by magick, Google presents you with a list of possible answers!

    MIND BLOWING!

    I have to tell you, this Google thing has changed my life because now I can be as dumb as a brick, and it doesn't matter! Google knows all!

    Having said that, since there are php functions that do this domain name thingy, regex would not be my first choice...

    And you know, come to think about it, there's another resource I seem to use a lot, it's this thingy right HERE, I'm guessing from having read a lot of your questions, that you don't know about it.

    Cheers!
    Last edited by Arty Zifferelli; November 12th, 2017 at 10:45 PM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    410
    Rep Power
    8
    Originally Posted by Arty Zifferelli
    I'm sorry, but have you not heard of this new thing called Google? Serious question: Ever used it?

    The reason I asked is that while I don't know for sure because it wouldn't be my method of choice, I do indeed suspect that it can be done with regex - since everything can be done with regex - and the first thing I would do would be to "Google" it.

    To "Google" is a verb. Basically, you navigate to https://www.Google.com, enter your question into the little box, and than clicky the "Google Search" button.

    Here's a picture => google.png No, you awful people, it is not Goatse...

    Amazing things happen! As if by magick, Google presents you with a list of possible answers!

    MIND BLOWING!

    I have to tell you, this Google thing has changed my life because now I can be as dumb as a brick, and it doesn't matter! Google knows all!

    Having said that, since there are php functions that do this domain name thingy, regex would not be my first choice...

    And you know, come to think about it, there's another resource I seem to use a lot, it's this thingy right HERE, I'm guessing from having read a lot of your questions, that you don't know about it.

    Cheers!
    Thanks for the php function link. yeah, you are right. I did not know about it because I avoid the php manual like the plague. It's too deep for a beginner and puts us off.
    As for google. Too many old and worn out code samples. Too many buggy code samples. Too many code samples with deprecated stuffs.
    Better to pester the likes of you in the forum and get upto date advice and upto date code samples.

    Btw, google ? Their algorithm power has really badly dropped in the last 5 yrs. And yet, most people use them. Wait till my searchengine algorithm is out. I won't be surprised if any searchengine tries buying my domain and algorithm out to compete with google with it. You already know by now that I intend to contend with the major searchengines and you know very well that I think my searchengine feature ideas are better than what exists today. You know that more than anyone else here. Infact, I put my searchengine on hold as I deem that project to be 2nd best and was busy with the one I deem 1st best. Now the 1st best one is out of the way, I'm getting back at my unique searchenguine project.
    Yeah, I know. With all that smart head of mine, why do I make comments like this that sounds childish and attracts people's despise. But you see, I like it. I like it when people try proving me wrong. That my ideas are naive. That my dreams are naive. That I'd never be able to thinkup unique features to contend with the big guys. I want them to group up and say all these things so one day I can prove them all wrong and say: I told you so!
    If you're a smart guy. Never show that you are. Else people will fear to compete with you. Act a little childish, attract competitions who think you'll be a sitting duck and then WHAM! Turn the tables around! Make 'em all the sitting ducks! Ya! Ya! Ya! (laughing like Bert Simpsons now)
    An idea just popped-up in my head! Going to build a social network, forum, etc. where instead of using smileys you'll use voiceys to show your emotions (like the laugh I just mentioned). Good idea!
    Last edited by UniqueIdeaMan; January 8th, 2018 at 10:00 AM.
  12. #7
  13. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,344
    Rep Power
    2063
    Originally Posted by UniqueIdeaMan
    Thanks for the php function link. yeah, you are right. I did not know about it because I avoid the php manual like the plague. It's too deep for a beginner and puts us off.
    As for google. Too many old and worn out code samples. Too many buggy code samples. Too many code samples with deprecated stuffs.
    Better to pester the likes of you in the forum and get upto date advice and upto date code samples.
    The PHP manual online is the BEST resource that you can think of. It tells you exactly what every function does. and exactly what to expect from every function. The fact that you don't know how to use it says more about you then it could ever say about PHP itself...

    Originally Posted by UniqueIdeaMan
    Btw, google ? Their algorithm power has really badly dropped in the last 5 yrs. And yet, most people use them. Wait till my searchengine algorithm is out. I won't be surprised if any searchengine tries buying my domain and algorithm out to compete with google with it. You already know by now that I inetend to contend with the major searchengines and you know very well that I think my searchengine feature ideas are better than what exists today. You know that more than anyone else here.
    So tell us, what's the URL of your amazing search engine that's going to catalogue and index every website out there?

    You don't have it. How do I know? Because you do not have the budget for server farms like that. I'm not saying that you won't get there, but you will never build a Google-killer out of the box.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    410
    Rep Power
    8
    Originally Posted by Catacaustic
    The PHP manual online is the BEST resource that you can think of. It tells you exactly what every function does. and exactly what to expect from every function. The fact that you don't know how to use it says more about you then it could ever say about PHP itself...



    So tell us, what's the URL of your amazing search engine that's going to catalogue and index every website out there?

    You don't have it. How do I know? Because you do not have the budget for server farms like that. I'm not saying that you won't get there, but you will never build a Google-killer out of the box.
    I'm not going to index every url in the world to begin with. I'll experiment with my algorithm and create a comparison site where there would be many search boxes. Each from each searchengine so people can test each. My one would be present. They'd see either my one yields no results because it has not indexed enough sites to yield results based on the KWs or they'll see that whatever it yields, it is mroe accurate than the major searchengines.
    That will speak volumes. Sooner or later, people would recommend my searchengine to others. I'll add a viral recommendation feature. Then the major searchengines would start noticing that people are starting to vote for mine over their's. They'll get scared they'd lose a huge chunk of the market to me. And so, I won;t be surprised if they start bidding to buy mine out.
    As for my SE, it is not finished yet.

    I like you Catacaustic, you always skeptical and try putting me off from my ventures. But you try putting me off by reasoning and that is feed back for me. If I miss anything (a loop hole in my plan) then you'd find it and point it out. And, if you fail to find a loop hole then that tells me volumes. It tells me, my project is now near fool proof and worthy to be out there pounding the net.
    Keep in touch. Keep up the skepticism and your fair and mannered criticisms.

    PS - You'd gicen me an urge to proove things to you. At the back of my head, I'll be pondering ways how to seriously defeat the major searchengines now so they never come anywhere near my algorithm greatness.
    And no, it's not "all talk!". I'm a mind reader and a predictor. I know what people think and can predict what they will be thinking. That is why, I have an edge over my competitions. Always.
    Anyway, I have a Mysql question and gonna open a new thread. I'll see you there.

    I'm now pondering how to be the death of searchengines so people don't use them any more.
    First came link directories like Yahoo and Open Directory (dmoz). People used them always. Then came along the first searchengine webcrawler.com and revolutionised the way people search and find links that lead to the demise of the link directories. Then came along with ppc searchengines like overture.com and 7search.com. Then the price comparison searchengines like shopping.com. One after the other. But none of them have been able to defeat the searchengine (webcrawler.com alike).
    Therefore, my one has to be unique like the others but must have enough muscle power to totally annihialate the crawler & indexer. Let's see what I can come-up with. I like these sort of challenges. Keeps me on my foot. Or, should I say: "Keeps me on my brains" ? Lol!
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    410
    Rep Power
    8
    Originally Posted by Catacaustic
    The PHP manual online is the BEST resource that you can think of. It tells you exactly what every function does. and exactly what to expect from every function. The fact that you don't know how to use it says more about you then it could ever say about PHP itself...



    So tell us, what's the URL of your amazing search engine that's going to catalogue and index every website out there?

    You don't have it. How do I know? Because you do not have the budget for server farms like that. I'm not saying that you won't get there, but you will never build a Google-killer out of the box.
    I'm not going to index every url in the world to begin with. I'll experiment with my algorithm and create a comparison site where there would be many search boxes. Each from each searchengine so people can test each. My one would be present. They'd see either my one yields no results because it has not indexed enough sites to yield results based on the KWs or they'll see that whatever it yields, it is mroe accurate than the major searchengines.
    That will speak volumes. Sooner or later, people would recommend my searchengine to others. I'll add a viral recommendation feature. Then the major searchengines would start noticing that people are starting to vote for mine over their's. They'll get scared they'd lose a huge chunk of the market to me. And so, I won't be surprised if they start bidding to buy mine out.
    As for my SE, it is not finished yet.

    I like you Catacaustic, you always skeptical and try putting me off from my ventures. But you try putting me off by reasoning and that is feed back for me. If I miss anything (a loop hole in my plan) then you'd find it and point it out. And, if you fail to find a loop hole then that tells me volumes. It tells me, my project is now near fool proof and worthy to be out there pounding the net.
    Keep in touch. Keep up the skepticism and your fair and mannered criticisms.

    I'm now pondering how to be the death of searchengines so people don't use them any more.
    First came link directories like Yahoo and Open Directory (dmoz). People used them always. Then came along the first searchengine webcrawler.com and revolutionised the way people search and find links that lead to the demise of the link directories. Then came along with ppc searchengines like overture.com and 7search.com. Then the price comparison searchengines like shopping.com. One after the other. But none of them have been able to defeat the searchengine (webcrawler.com alike).
    Therefore, my one has to be unique like the others but must have enough muscle power to totally annihialate the crawler & indexer. Let's see what I can come-up with. I like these sort of challenges. Keeps me on my foot. Or, should I say: "Keeps me on my brains" ? Lol!
    Actually, the real power and challenge would be to build one that nobody can copy. An "immune from copying" one. That is more a challenge. I'm starting to like all this. And no, I'm not digging my own grave nor shooting myself on my foot.
    I'm jus curious Catacaustic, if for some reason I manage to build something unique with php and even if I fail to defeat the big guys, would you start takign me seriously if you start seeing either one of the following coming true ?

    * Large number of people voting for my idea and suggesting the major ones to update to like mine;
    * Percentagewise more people are making money and/or a living using my .......compared to how many people are making money or a living using the major ones;
    * For some reason you like my ........ even if the above mentioned 2 prove false;
    * You deem my idea is unique even if the above mentioned 3 prove false;


    PS - You'd given me an urge to prove things to you. At the back of my head, I'll be pondering ways how to seriously defeat the major searchengines now so they never come anywhere near my algorithm greatness.
    And no, it's not "all talk!". I'm a mind reader and a predictor. I know what people think and can predict what they will be thinking. That is why, I have an edge over my competitions. Always.
    Anyway, I have a Mysql question and gonna open a new thread. I'll see you there.
    Last edited by UniqueIdeaMan; January 8th, 2018 at 10:27 AM.

IMN logo majestic logo threadwatch logo seochat tools logo