I have a field in which I ask for desired domain name, now it came to a point that some user includes http://www.desireddomain on the field. Having this value, the domain registrar API I have will return an error. The approach I have in mind is to omit any characters before period (including period), using preg_replace(). I have a <select> which contains (.com,.biz,.org,.net)
$desired_domain = "www.desireddomain"; // user input
$will_be = "desireddomain"; // final output after preg_replace() ?
And also, does this limits me to only the period or is there anything more I should know? Thanks.
You don’t need to use regular expressions since you are aren’t doing a “fuzzy” search. Just get everything from the last period on, if there is a period.
Alternatively, if you want to make sure they didn’t enter .com,.biz,.org,.net, use explode and do a check.
In this example, they are asking to use “com” as the domain, even though it’s no valid. You could create a loop instead, where you continuously pop items off the array until you find a valid part or run out of items.