Your script would need to be able to access your httpd.conf file on the server and create a virtual host entry. Something like....
<VirtualHost *:80>
DocumentRoot /home/optix/www
DirectoryIndex index.php
ServerAdmin
optix@email.com
ServerName sub.mydomain.com
ServerSignature email
</VirtualHost>
OR
under the domain name's Virtual Host entry, just keep adding server aliases....
<VirtualHost *:80>
DocumentRoot /home/optix/www
DirectoryIndex index.php
ServerAdmin
optix@email.com
ServerName mydomain.com
ServerAlias sub2.mydomain.com
ServerAlias sub3.mydomain.com
ServerAlias sub4.mydomain.com
ServerAlias sub5.mydomain.com
ServerAlias sub6.mydomain.com
ServerAlias sub7.mydomain.com
ServerSignatureemail
</VirtualHost>
Then close and save the httpd.conf file.
It looks like you'd also need to have the script create a user first, so you, your script would need to be able to execute a few commands, example.....
I'm sure there's a more efficient way to do that but you should get what I mean.