preg_match to a whois server response

  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 322
  • Loc: Canada

Post 3+ Months Ago

Hi All

I got a situation that seems simple but I cannot solve it.

I have a php script that that checks with a WHOIS server to see if a domain name is available or regestered.

When I test I get the following response from the whois server if the domain is available( there is of course much more information also which I do not use):

Domain status: available

I then set up the following:

$available = "Domain status: available";
$response = all the text output received from the whois server

I then set up the following:

Code: [ Select ]
If(preg_match("/$available/", $response, $match))
{
print_r($match);
}
?>
  1. If(preg_match("/$available/", $response, $match))
  2. {
  3. print_r($match);
  4. }
  5. ?>


When used as shown above $match output is blank:

Array ()

if I change to $available = "Domain status:"
then $match gives:

Array ( [0] => Domain status: )

I then changed to $available = "available"
then $match gives:

Array ( [0] => available )

I then decided to create a standalone script and copied and pasted the whois server output to my variable as follows:

Code: [ Select ]
$available = "Domain status: available";
// I pasted the whois server response to my variable
$response = "Domain status: available";
If(preg_match("/$available/", $response, $match))
{
print_r($match);
}
  1. $available = "Domain status: available";
  2. // I pasted the whois server response to my variable
  3. $response = "Domain status: available";
  4. If(preg_match("/$available/", $response, $match))
  5. {
  6. print_r($match);
  7. }


I then got the following $match output:

Array ( [0] => Domain status: available )

If I try to match directly with the whois server response I cannot seem to do it, which appears due to the colon : separation.

However, if I copy and paste on separate script, it works.

Unfortunately, I cannot use just the response "available" as it appears many times, whether the domain is available or not available. There is really no way to try and determine which "available" I need to use from the whois server response.

Could someone explain why I have this situation and what I could possibly do about. I really need to use "Domain status: available" if my script is to work properly.

Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Look for the position of "Domain status", then look for the presence of "available" in the 30-ish character substring starting from that position.

Code: [ Select ]
$position_of_ds = strpos($response, 'Domain status');
if($position_of_ds === false)
{
  exit;
}

$focused_on = substr($response, $position_of_ds, 30);
if(strpos($focused_on, 'available') !== false)
{
  echo 'Domain available';
}
  1. $position_of_ds = strpos($response, 'Domain status');
  2. if($position_of_ds === false)
  3. {
  4.   exit;
  5. }
  6. $focused_on = substr($response, $position_of_ds, 30);
  7. if(strpos($focused_on, 'available') !== false)
  8. {
  9.   echo 'Domain available';
  10. }
  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1241
  • Loc: Sydney

Post 3+ Months Ago

SSssssoooo What ya making? :P
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 322
  • Loc: Canada

Post 3+ Months Ago

Hi joebert

I adapted your suggestion to my problem and got things working.

Thanks for all your help

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 163 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.