mongmong seesee mongmong seesee - 7 months ago 16
PHP Question

Why can not use preg_match php with fsockopen response data?

Why can not use

preg_match
php with
fsockopen
response data ?

I tried to use
preg_match
with
$response
for get expires date.

But not work , how can i do ?

<?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;
?>


note:

When i echo
$response
it's will be look like

: 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.

Answer

You need to use the s regexp modifier to make . match newline characters. Also, there's no space before >>> Last update in the whois output.

This works.

$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;