首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么不能在fsockopen响应数据中使用preg_match php?

为什么不能在fsockopen响应数据中使用preg_match php?
EN

Stack Overflow用户
提问于 2016-04-22 15:23:44
回答 2查看 66关注 0票数 1

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

我尝试将preg_match$response一起用于get过期日期。

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

代码语言:javascript
复制
<?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时,它看起来就像

代码语言:javascript
复制
: 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.
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-04-22 15:30:09

您需要使用s regexp修饰符使.匹配换行符。而且,在>>> Last update输出中没有任何空间。

这个很管用。

代码语言:javascript
复制
$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;
票数 4
EN

Stack Overflow用户

发布于 2016-04-22 15:30:10

尝试:

代码语言:javascript
复制
preg_match('/Expiration Date: (.*?)\s/s', $response,$expires_date_month_year);
echo $expires_date_month_year[1];
//26-dec-2016
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36797710

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档