Welcome to PHP Smarty Q&A, where you can ask programmaing questions and receive answers from other members of the community for PHP, Smarty, MYSQL related. You can also share or save your scripts in this repository for future reference.

Get Domain Expiration Date in PHP

+1 vote
82 views

I would like to get only a domain expiration date from the following script, can anyone help please.

https://helgesverre.com/blog/how-to-query-whois-servers-with-php/

<?php
 
// Open a Socket connection to our WHOIS server
$fp = fsockopen("whois.verisign-grs.com", 43);
 
// The data we're sending
$out = "helgetech.com\r\n";
 
// Send the data
fwrite($fp, $out);
 
// Listen for data and "append" all the bits of information to 
// our result variable until the data stream is finished
// Simple: "give me all the data and tell me when you've reached the end"
while (!feof($fp)) {
	$whois .= fgets($fp, 128);
}
 
 
// Print out the data we've received
echo "<pre>";
echo $whois;
echo "</pre>";
 
// Close the Socket Connection
fclose($fp);
 
?>

 

asked Jun 28, 2016 in PHP by anonymous

1 Answer

0 votes
 
Best answer

If you just want to get the expiration date from the script, you should use `preg_match`.

its untested, try this.

<?php

// Open a Socket connection to our WHOIS server
$fp = fsockopen("whois.verisign-grs.com", 43);
 
// The data we're sending
$out = "smsgatewaycenter.com\r\n";
 
// Send the data
fwrite($fp, $out);
 
// Listen for data and "append" all the bits of information to 
// our result variable until the data stream is finished
// Simple: "give me all the data and tell me when you've reached the end"
while (!feof($fp)) {
	$whois .= fgets($fp, 128);
}
$result = preg_match('/^.*\Expiration Date\b.*$/m', $whois, $matches);
 
// Print out the data we've received
echo "<pre>";
echo $matches[0];
echo "</pre>";
 
// Close the Socket Connection
fclose($fp);

Hope this helps!

answered Jun 28, 2016 by robert (13,210 points)
...