如何使用 PHP 和 jQuery 检查变量是否包含有效的 url?
我正在尝试制作一个 whois 检查脚本。
用户可以提交一些域名地址,然后收到一条消息(如果可用或不可用)。
$_POST['url']
是用户提交的值。
我怎么知道这个变量是不是域名地址呢?
对于以下域,它应该给出 true
:
http://google.com
www.google.com
http://www.google.com
google.com
对于 javascript 也是如此(我也使用 ajax-validation)?
I'm trying to make a whois check script.
User can submit some domain address and then get a message if it's available or not.
$_POST['url']
is the submitted value by user.
How do I know if this variable is a domain name address?
It should give true
for domains like:
http://google.com
www.google.com
http://www.google.com
google.com
Same for javascript (I'm using ajax-validation also)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想检查网址是否为有效网址,您可以使用
filter_var ()
与FILTER_VALIDATE_URL< /代码>
筛选。
If you want to check if the url is a valid url you could use
filter_var()
with theFILTER_VALIDATE_URL
filter.您可以使用以下代码:
示例:
You can use the following code:
Example: