That’s pretty impossible , take a look at what i found at stackoverflow :-
1) if you have cPanel then you can use what i used.
very simple function provided my hosting company server guy.
As the other use said i agree that php cannot do anything with this…
These functions call cPanel libraries indirectly and those functions can access server level functions because they will have permission to do that.
2)PHP has nothing to do with domain or subdomains. You have to configure your server application accordingly to achieve this.
If you are using apache, take a look in their documentation about vhosts.