PHP does not control the server, it only runs on it. However, PHP can be used to modify the configuration files for the server. The modifications will depend upon the server (Apache, IIS, etc.).
Configure your apache/other-web-server for wildcard subdomain. Then your PHP script can read the subdomain using $_SERVER['HTTP_HOST] and can serve the data accordingly.
Comment