Jump to content

subdomain regex


Go to solution Solved by requinix,

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

  • Solution

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.