干净的主机名
我有一个字段要求输入所需的域名,现在有些用户在该字段中包含 www.desireddomain。有了这个值,我的域名注册商 API 将返回错误。我想到的方法是使用 preg_replace() 省略句点(包括句点)之前的任何字符。我有一个
$desired_domain = "www.desireddomain"; // user input
$will_be = "desireddomain"; // final output after preg_replace() ?
而且,这是否将我限制为仅限句点,还是还有什么我应该知道的?谢谢。
I have a field in which I ask for desired domain name, now it came to a point that some user includes 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您不需要使用正则表达式,因为您没有进行“模糊”搜索。如果有一个周期的话,就获取最后一个周期的所有内容。
或者,如果您想确保他们没有输入.com、.biz、.org、.net,请使用explode 并进行检查。
在此示例中,他们要求使用“com”作为域,即使它无效。您可以创建一个循环,不断从数组中弹出项目,直到找到有效部分或用完项目。
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.