jj20051 Posted July 26, 2010 Share Posted July 26, 2010 I have a username generator that takes the first 8 characters from an entered domain name to make the username. How would I change it so that if the domain begins with a number it adds a "t" or something similar t the username? $username = preg_replace("/[\.,\";'\:]/", "", $domain); $username = substr($username, 0, ; Between those two lines it would have to add the letter to the front of the username if the username started with a number... Examples: example.com ---> Username: exampleco 0303mg.org ---> Username: t0303mgo my0domains.com ---> Username: my0domai 002domain.com ---> Username: t002doma Hopefully you understand what I'm trying to do... Link to comment https://forums.phpfreaks.com/topic/208881-if-it-starts-with-a-number-change-it/ Share on other sites More sharing options...
Goat Posted July 26, 2010 Share Posted July 26, 2010 There's probably more elegant regex solution, but this works: $username = preg_replace("/[\.,\";'\:]/", "", $domain); if( is_numeric(substr($username, 0, 1)) ) { $username .= 't'.$username; } $username = substr($username, 0, ; regards, Goat Link to comment https://forums.phpfreaks.com/topic/208881-if-it-starts-with-a-number-change-it/#findComment-1091096 Share on other sites More sharing options...
icez Posted July 26, 2010 Share Posted July 26, 2010 ... Link to comment https://forums.phpfreaks.com/topic/208881-if-it-starts-with-a-number-change-it/#findComment-1091100 Share on other sites More sharing options...
jj20051 Posted July 26, 2010 Author Share Posted July 26, 2010 Very cool, and right in front of me, thanks Link to comment https://forums.phpfreaks.com/topic/208881-if-it-starts-with-a-number-change-it/#findComment-1091110 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.