gpt4 book ai didi

php - 编写域查找工具

转载 作者:搜寻专家 更新时间:2023-10-31 21:17:43 24 4
gpt4 key购买 nike

我一直在编写一个域检查程序,并且真的坚持使用 php。这是我到目前为止所拥有的:

<?php
set_time_limit(0);
ob_start();
$domain = $_GET['domain'];
########### Extensions to be checked
$extensions = array(
'.com' => array('whois.crsnic.net','No match for'),
'.info' => array('whois.afilias.net','NOT FOUND'),
'.net' => array('whois.crsnic.net','No match for'),
'.co.uk' => array('whois.nic.uk','No match'),
'.nl' => array('whois.domain-registry.nl','not a registered domain'),
'.ca' => array('whois.cira.ca', 'AVAIL'),
'.name' => array('whois.nic.name','No match'),
'.ws' => array('whois.website.ws','No Match'),
'.be' => array('whois.ripe.net','No entries'),
'.org' => array('whois.pir.org','NOT FOUND'),
'.biz' => array('whois.biz','Not found'),
'.tv' => array('whois.nic.tv', 'No match for'),
);
###########

if(isset($domain))
{
$newdomain = str_replace(array('www.', 'http://'), NULL, $domain);
$finaldomain = str_replace($extensions, NULL, $newdomain);

if(strlen($finaldomain) > 0)
{
foreach($extensions as $extension => $who)
{
$buffer = NULL;

$sock = fsockopen($who[0], 43) or die('Error Connecting To Server:' . $server);
fputs($sock, $finaldomain.$extension . "\r\n");

while( !feof($sock) )
{
$buffer .= fgets($sock,128);
}

fclose($sock);

if(eregi($who[1], $buffer))
{
echo '<h4 class="available"><span>Available</span>' . $finaldomain. '<b>' . $extension .'</b> is Available</h4>';
}
else
{
echo '<h4 class="taken"><span>Taken</span>' . $finaldomain . '<b>' .$extension .'</b> is Taken</h4>';
}
echo '<br />';

ob_flush();
flush();
sleep(0.3);

}
}
else
{
echo 'Please enter the domain name';
}
}
?>

我遇到的问题是我不知道如何从传递的域中删除扩展名。

然后当它返回结果时,我希望他们输入的扩展名是结果列表中的第一个。

我是 php 新手,但我的项目需要这个。感谢所有帮助。

谢谢乔

最佳答案

首先,后缀被称为顶级域(简称TLD)。其次,.co.uk 不是顶级域,.uk 是。它还具有其他子域,如 .org.uk.gov.uk 等。

现在,要返回文件名/域名的扩展名 部分,您可以使用pathinfo :

$tld = pathinfo('helloworld.co.uk', PATHINFO_EXTENSION);
echo $tld; // uk

您可能需要修改您的数组以删除您放置在那里的标题点,或者简单地:

$tld = '.' . pathinfo('helloworld.co.uk', PATHINFO_EXTENSION);
$whois_server = $extensions[$tld];

关于php - 编写域查找工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5022057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com