为什么不能将 preg_match php 与 fsockopen 响应数据一起使用


Why can not use preg_match php with fsockopen response data?

为什么不能将preg_match php与fsockopen响应数据一起使用?

我尝试将preg_match$response一起使用以获取到期日期。

但是不工作,我该怎么办?

<?PHP
    $server = "whois.verisign-grs.com";
    $domain_check = "stackoverflow.com";
    $con = fsockopen($server, 43);
    if (!$con) return false;
    fputs($con, $domain_check."'r'n");
    $response = ' :';
    while(!feof($con)) 
    {
        $response .= fgets($con,128); 
    }
    // echo $response;
    preg_match('/Expiration Date: (.+?) >>> Last update of whois database/',$response,$expires_date_month_year);
    $expires_date_month_year_val = $expires_date_month_year[1];
    echo $expires_date_month_year_val;
?>

注意:

当我回声$response时,它会看起来像

: Whois Server Version 2.0 Domain names in the .com and .net domains can now be registered with many different competing registrars. Go to http://www.internic.net for detailed information. Domain Name: STACKOVERFLOW.COM Registrar: NAME.COM, INC. Sponsoring Registrar IANA ID: 625 Whois Server: whois.name.com Referral URL: http://www.name.com Name Server: CF-DNS01.STACKOVERFLOW.COM Name Server: CF-DNS02.STACKOVERFLOW.COM Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited Updated Date: 26-nov-2015 Creation Date: 26-dec-2003 Expiration Date: 26-dec-2016 >>> Last update of whois database: Fri, 22 Apr 2016 15:30:45 GMT <<< For more information on Whois status codes, please visit https://icann.org/epp NOTICE: The expiration date displayed in this record is the date the registrar's sponsorship of the domain name registration in the registry is currently set to expire. This date does not necessarily reflect the expiration date of the domain name registrant's agreement with the sponsoring registrar. Users may consult the sponsoring registrar's Whois database to view the registrar's reported date of expiration for this registration. TERMS OF USE: You are not authorized to access or query our Whois database through the use of electronic processes that are high-volume and automated except as reasonably necessary to register domain names or modify existing registrations; the Data in VeriSign Global Registry Services' ("VeriSign") Whois database is provided by VeriSign for information purposes only, and to assist persons in obtaining information about or related to a domain name registration record. VeriSign does not guarantee its accuracy. By submitting a Whois query, you agree to abide by the following terms of use: You agree that you may use this Data only for lawful purposes and that under no circumstances will you use this Data to: (1) allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via e-mail, telephone, or facsimile; or (2) enable high volume, automated, electronic processes that apply to VeriSign (or its computer systems). The compilation, repackaging, dissemination or other use of this Data is expressly prohibited without the prior written consent of VeriSign. You agree not to use electronic processes that are automated and high-volume to access or query the Whois database except as reasonably necessary to register domain names or modify existing registrations. VeriSign reserves the right to restrict your access to the Whois database in its sole discretion to ensure operational stability. VeriSign may restrict or terminate your access to the Whois database for failure to abide by these terms of use. VeriSign reserves the right to modify these terms at any time. The Registry database contains ONLY .COM, .NET, .EDU domains and Registrars.
您需要

使用 s 正则表达式修饰符来.匹配换行符。此外,在 whois 输出中>>> Last update之前没有空格。

这行得通。

$server = "whois.verisign-grs.com";
$domain_check = "stackoverflow.com";
$con = fsockopen($server, 43);
if (!$con) return false;
fputs($con, $domain_check."'r'n");
$response = ' :';
while(!feof($con)) 
{
    $response .= fgets($con,128); 
}
// echo $response. '<br><br>';
preg_match('/Expiration Date: (.+?)>>> Last update of whois database/s',$response,$expires_date_month_year);
$expires_date_month_year_val = $expires_date_month_year[1];
echo $expires_date_month_year_val;

尝试:

preg_match('/Expiration Date: (.*?)'s/s', $response,$expires_date_month_year);
echo $expires_date_month_year[1];
//26-dec-2016