URL = http://company.website.com/pages/users/add/
How do i find the subdomain from this via PHP
Such that $subdomain = 'company'
And $url = '/pages/users/add/'
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ll want to take a look at PHP’s parse_url. This will give you the basic components of the URL which will make it easier to parse out the rest of your requirements (the subdomain)
And then a simple regex* to parse
$url_parsed['host']for subdomains:* I tested the regex in JavaScript, so you may need to tweak it a little.