What exactly do you mean? If I understand this correct, you want to add subdomains from within PHP? You'll have to read the right zone-files and add a record, however, I don't think you can access these files from php... (but then again, what do I know? :p)
I suggest you just put *.domain.tld in the DNS, point that to the right virtual domain (or whatever), and make an index.php that does something like this :
$splitdomain = split(".",$HTTP_HOST);
$subdomain = $splitdomain[0];
and, depending on the content of $subdomain do a redirect (something like this🙂
header ("Location: $subdomain/index.php");
Or did I misnderstand your question? Probably...