Destramic Posted July 21, 2015 Share Posted July 21, 2015 I'm guessing regex would be best for this as i can't see a php function for the job, but what i want to do is check if a string matches as being a valid domain. does anyone know a good pattern or a better solution to this please? I've seen a lot of patterns when searching but with little experience in regex i wouldn't know which one would be the strongest pattern. thank you Quote Link to comment https://forums.phpfreaks.com/topic/297412-subdomain-regex/ Share on other sites More sharing options...
requinix Posted July 21, 2015 Share Posted July 21, 2015 "Valid domain" is broader than you probably realize, what with IP addresses and IDNs and such. How are you going to use this and how strict/precise does it need to be? Quote Link to comment https://forums.phpfreaks.com/topic/297412-subdomain-regex/#findComment-1517022 Share on other sites More sharing options...
Destramic Posted July 21, 2015 Author Share Posted July 21, 2015 it doesn't need to be overly strict...it would probably be better if i explained what i wanted to do. ok well for my mvc routing system i want to know if a route i add is a domain or not ie. Router::add_route('shop.bisi.bid', array('controller' => 'shop', 'action' => 'items' )); then i can add that route into a sub domain array hope this explains things a little better...thanks Quote Link to comment https://forums.phpfreaks.com/topic/297412-subdomain-regex/#findComment-1517030 Share on other sites More sharing options...
Solution requinix Posted July 21, 2015 Solution Share Posted July 21, 2015 (edited) There's a lot of overlap though. "foo.jpg" is actually a valid domain name (which does not exist but that's not the point). So is "localhost". I'd say the determination between domain name and path should be done explicitly in code. For starters I wouldn't expect domains to be mixed up in routes - more like routes are added to configured domains. But with your current structure I'd think something like public function add_route($path, array $args, $domain = null) Router::add_route('/', array('controller' => 'shop', 'action' => 'items'), 'shop.bisi.bid'); Edited July 21, 2015 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/297412-subdomain-regex/#findComment-1517037 Share on other sites More sharing options...
Destramic Posted July 25, 2015 Author Share Posted July 25, 2015 well i think the way you've suggested is more a practical...dunno why i always try to over complicate things. thanks requinix Quote Link to comment https://forums.phpfreaks.com/topic/297412-subdomain-regex/#findComment-1517353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.