PHP gets whois information for a domain name

Source: Internet
Author: User
Tags explode

    • Let's start by understanding several file manipulation functions:
    • The fwrite () function writes to the file (which is safe for binary files).

Fwrite () writes the contents of the string to the file pointer. If length is specified, the write stops when the length byte is written or after the string is written, depending on which situation is encountered first. Fwrite () returns the number of characters written, or False if an error occurs.

  <? PHP   $file fopen ("Test.txt", "W");   Echo fwrite ($file, "Hello world. testing! " );   fclose ($file);  ? >

    • The feof (file) function detects whether the end of the file (EOF) has been reached.

  Returns an error (including the socket timeout) if the file pointer goes to EOF or if an error occurs, otherwise returns FALSE. The file parameter is a document pointer. The file pointer must be valid and must point to a file that was successfully opened by fopen () or Fsockopen () (but not yet fclose () closed).
  Tip: the feof () function is useful for traversing data with unknown length.
  NOTE: If the server does not close the connection opened by Fsockopen (), feof () waits until the timeout expires and returns TRUE. The default time-out limit is 60 seconds, and you can use Stream_set_timeout () to change the value.
  NOTE: If the passed file pointer is invalid, it may fall into an infinite loop because EOF does not return TRUE.

  <? PHP   $file fopen ("Test.txt", "R");   // prints all the lines in the text until the end of the file. while  feof($file)) {  echofgets( $file). "<br/>";  } W  fclose($file);  ? >

    • The fputs () function writes to the file (which is safe for binary files). The fputs () function is an alias for the fwrite () function.

Fputs (File,string,length)

  <? PHP   $file fopen ("Test.txt", "W");   Echo fputs ($file, "Hello world. testing! " );   fclose ($file);  ? >

    • Fgets () reads a row from the file pointed to by the files and returns a string of up to length-1 bytes in length. Stop after encountering a newline character (included in the return value), EOF, or having read the length-1 byte (to see the case first). If length is not specified, the default is 1 K, or 1024 bytes. If it fails, it returns false.
  <? PHP   $file fopen ("Test.txt", "R");    while feof ($file))  {  echofgets($file). "<br/>";  }   fclose ($file);  ? >
    • The FGETSS () function reads a row from an open file and filters out HTML and PHP tags. As with Fgets (), the difference is that FGETSS attempts to remove any HTML and PHP markup from the text that is being read.

FGETSS (file,length,tags) can use the optional third parameter tags to specify which tags are not removed. If it fails, it returns false.

  <? PHP   $file fopen ("Test.htm", "R");   Echo FGETSS ($file, 1024x768, "<p>,<b>");   fclose ($file);  ? >

Here's the code to get whois information

functionWhois_query ($domain) {    //Fix the domain name:    $domain=Strtolower(Trim($domain)); $domain=Preg_replace('/^http:\/\//i ', ',$domain); $domain=Preg_replace('/^www\./i ', ',$domain); $domain=Explode(‘/‘,$domain); $domain=Trim($domain[0]); //split the TLD from domain name    $_domain=Explode(‘.‘,$domain); $lst=Count($_domain)-1; $ext=$_domain[$lst]; //You find resources and lists//as these on Wikipedia://Http://de.wikipedia.org/wiki/Whois    $servers=Array(        "Biz" = "whois.neulevel.biz", "com" = "whois.internic.net", "us" = "whois.nic.us", "Coop" = "Whois.nic.coop", "info" = "Whois.nic.info", "name" = "Whois.nic.name", "Net" and "W" Hois.internic.net "," gov "=" whois.nic.gov "," edu "=" whois.internic.net "," mil "=" rs.in        Ternic.net "," int "=" whois.iana.org "," ac "=" whois.nic.ac "," ae "=" whois.uaenic.ae ", "At" = "whois.ripe.net", "au" and "whois.aunic.net", "Be" and "whois.dns.be", "BG" =&gt ; "Whois.ripe.net", "br" = "whois.registro.br", "BZ" and "Whois.belizenic.bz", "Ca" = "whois". Cira.ca "," cc "=" whois.nic.cc "," ch "=" whois.nic.ch "," cl "=" whois.nic.cl "," cn "= =" whois.cnnic.net.cn "," CZ "and" whois.nic.cz "," de "and" whois.nic.de "," fr "+" whois " . nic.fr "," Hu "= "whois.nic.hu", "ie" = "whois.domainregistry.ie", "il" = "whois.isoc.org.il", "in" =&gt ; "Whois.ncst.ernet.in", "ir" = "whois.nic.ir", "mc" = "whois.ripe.net", "to" and "=" Whois.toni  C.to "," TV "=" whois.tv "," Ru "and" whois.ripn.net "," org "=" whois.pir.org "," Aero " = "Whois.information.aero", "nl" = "whois.domain-registry.nl"    ); if(!isset($servers[$ext])) {         die(' Error:no matching NIC server found! '); }    $nic _server=$servers[$ext]; $output= ' '; //Connect to whois server:    if($conn=Fsockopen($nic _server, 43)) {        fputs($conn,$domain. "\ r \ n");  while(!feof($conn)) {            $output.=fgets($conn, 128); }        fclose($conn); } Else {         die(' Error:could not connect to '.$nic _server. ‘!‘); }    return $output;}$domain= ' www.qiangbi.net/a.html ';$output= Whois_query ($domain);Print_r($output);

PHP gets whois information for a domain name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.