Jump to content

subdomain regex


Destramic

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/297412-subdomain-regex/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/297412-subdomain-regex/#findComment-1517030
Share on other sites

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');
Link to comment
https://forums.phpfreaks.com/topic/297412-subdomain-regex/#findComment-1517037
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.