I tried this code: _______________________________________________________ $userid= "xxx-username23" $correctname = preg_replace("/[^a-zA-Z]/", "", $userid); $correctname2 = preg_replace('[xxx]', "", $correctname); echo $correctname2 ; result showing "username" _______________________________________________________ But i need the result = "username23", i am trying to remove only "xxx-" from $userid Please help.
As long as its xxx- this is all you need. $userid = "xxx-username23"; $correctname = preg_replace('#xxx-#', '', $userid); //replaces xxx- with nothing echo $correctname; //result showing "username23" PHP:
Or as long as the the username is separated with a - This will do: $userid = "12Ab-username23"; $correctname = preg_replace('#(.*-)#', '', $userid); //replaces xxx- with nothing echo $correctname; PHP:
If that's the only dash that can be in the user name you have lots of options: list($dummy, $correctname) = explode('-', $userid); echo $correctname; PHP: if the prefix you want to remove is always three chars long, just chop the string off: $correctname = substr($userid, 4); echo $correctname; PHP: