Define Account name from domain name


Every time a new customer registers for a new hosting plan, we send him an automatic email confirmation for the creation of his hosting plan and siteworx account.

Before, to allow him to access right now to his web site, we told him to update his /host file
Now as we can use adresse ip/~account_name we plan to upgrade our mail to give this method.

We use API to create siteWorx account, so we have a lot of informations as the IP and the domain name. But we don’t have the account name.
We do have to define it from the domain name, exactly as iworx do.

We have created a litlle PHP script to define from a domain name the account name

$delete = array("_", “-”, “.”);
echo $result = substr(str_replace($delete, “”, $domain),0,8);

so domain = titi50co

It works fine, but we’d like to be sure this is enough.
Not sure if iworx allows numeric data in the account name ?
is there others $delete chars to add than “-” “_” “.” ?

Thanks for your comments


Here’s the basics of what we do to convert a domain name to a username. Collisions are handled by making the 8th char an integer starting at 1:

    // just to be sure we don't have spaces
    $uniqname = trim( $domain );

    // all usernames are lowercase.
    $uniqname = strtolower( $uniqname );

    // first convert all numbers to their
    // text equivalent (i.e 1 -> one)
    $translate = array( '0' => 'zero',
			'1' => 'one',
			'2' => 'two',
			'3' => 'three',
			'4' => 'four',
			'5' => 'five',
			'6' => 'six',
			'7' => 'seven',
			'8' => 'eight',
			'9' => 'nine' );
    $uniqname = strtr( $uniqname, $translate );

    // now remove any non alpha chars (i.e. -, +, etc.)
    $uniqname = ereg_replace( '[^[:alpha:]]', '', $uniqname );

    // now truncate the domain name at 8 chars
    if( strlen( $uniqname ) > 8 ) {
      $uniqname = substr( $uniqname, 0, 8 );


lol I was sure our code was to easy :slight_smile:

thanks Chris