you probably wont be able to do it with php because it wont have access to the apache conf file or the dns zone file which would need to be changed in order to add the subdomain. the cleanest way to do this in my opinion is to just have your host set up a wildcard for you in the apache config file, and have it point to a folder of yours where you can set up the script that deals with what subdomain was visited and show the appropriate page.
the virtualhost entry might look something like this
<VirtualHost 1.2.3.4>
ServerAlias *.yoursite.com
ServerAdmin you@yoursite.com
DocumentRoot /home/yoursite/public_html/subdomains
</VirtualHost>
now when someone access any subdomain it loads the index page from the subdomains folder, in there you put your php script that serves the appropriate content. you can determine which subdomain they visited by using $_SERVER['HTTP_HOST'] and seeing which subdomain was accessed.