title: Fatal error: Uncaught InvalidArgumentException:
body: <p>Good afternoon, I just started working with domains in PHP.
  The code isn't finished yet but before I try to put it inside a database I want it to properly work. But I got a fatal error and if I proceed I'll get a 404 not found error. The fatal error is this:</p>
  <blockquote>
  <p>Fatal error: Uncaught InvalidArgumentException: Invalid syntax in C:\xampp\htdocs\login\Classes\domain.php:23 Stack trace:</p>
  <p>0 C:\xampp\htdocs\login\logins.php(25): Whois-&gt;__construct('')</p>
  <p>1 {main} thrown in C:\xampp\htdocs\login\Classes\domain.php on line 23</p>
  </blockquote>
  <p>The line of code in question is this:</p>
  <pre><code>$whois_answer = $domain-&gt;info();
  </code></pre>
  <p>I really don't know how to fix this one...</p>
  <pre><code>&lt;?php
              require (&quot;Classes/domain.php&quot;);
          
              $search = &quot;&quot;;
              echo &quot;&lt;form action='login.php' method='get'&gt;&quot;;
              echo &quot;&lt;p&gt;Qual é o domínio que deseja procurar?&lt;/p&gt;&lt;br&gt;&quot;;
              echo &quot;&lt;input type='text' name='search' value=''&gt;&lt;br&gt;&lt;br&gt;&quot;;
              echo &quot;&lt;input type='submit' name='search2' value='Procurar'&gt;&quot;;
              echo &quot;&lt;/form&gt;&quot;;
              if (!empty ($_GET['search'])){
                  $search = $_GET['search'];
              }
              $sld = $search;
              //var_dump($search);
              
              //$sld = 'larousse.fr';
              $domain = new Whois($sld);
              
              $whois_answer = $domain-&gt;info();
              
              $answer= preg_split(&quot;/\r\n|\n|\r/&quot;, $whois_answer);
  </code></pre>
  <p>and the domain.php:</p>
  <pre><code>&lt;?php
  class Whois
  {
      private $domain;
      private $TLDs;
      private $subDomain;
      private $servers;
  
      public function __construct($domain)
      {
          $this-&gt;domain = $domain;
          if ( preg_match('/^([\p{L}\d\-]+)\.((?:[\p{L}\-]+\.?)+)$/ui', $this-&gt;domain, $matches) || preg_match('/^(xn\-\-[\p{L}\d\-]+)\.(xn\-\-(?:[a-z\d-]+\.?1?)+)$/ui', $this-&gt;domain, $matches)){
          $this-&gt;subDomain = $matches[1];
          $this-&gt;TLDs = $matches[2];
      } else
          throw new \InvalidArgumentException(&quot;Invalid $domain syntax&quot;);
        $this-&gt;servers = json_decode(file_get_contents(__DIR__.'/whois.servers.json' ), true);
  }
  public function info()
  {
      if ($this-&gt;isValid()) {
          $whois_server = $this-&gt;servers[$this-&gt;TLDs][0];
          if ($whois_server != '') {
              if (preg_match(&quot;/^https?:\/\//i&quot;, $whois_server)) {
                  $ch = curl_init();
                  $url = $whois_server . $this-&gt;subDomain . '.' . $this-&gt;TLDs;
                  curl_setopt($ch, CURLOPT_URL, $url);
                  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
                  curl_setopt($ch, CURLOPT_TIMEOUT, 60);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                  $data = curl_exec($ch);
                  if (curl_error($ch)) {
                      return &quot;Connection error!&quot;;
                  } else {
                      $string = strip_tags($data);
                  }
                  curl_close($ch);
              } else {
                  $fp = fsockopen($whois_server, 43);
                  if (!$fp) {
                      return &quot;Connection error!&quot;;
                  }
                  $dom = $this-&gt;subDomain . '.' . $this-&gt;TLDs;
                  fputs($fp, &quot;$dom\r\n&quot;);
                  $string = '';
                  if ($this-&gt;TLDs == 'com' || $this-&gt;TLDs == 'net') {
                     while (!feof($fp)) {
                         $line = trim(fgets($fp, 128));
                         $string .= $line;
                         $lineArr = explode (&quot;:&quot;, $line);
                         if (strtolower($lineArr[0]) == 'whois server') {
                             $whois_server = trim($lineArr[1]);
                         }
                      }
                      $fp = fsockopen($whois_server, 43);
                      if (!$fp) {
                          return &quot;Connection error!&quot;;
                      }
                      $dom = $this-&gt;subDomain . '.' . $this-&gt;TLDs;
                      fputs($fp, &quot;$dom\r\n&quot;);
                      $string = '';
                      while (!feof($fp)) {
                          $string .= fgets($fp, 128);
                      }
                  } else {
                      while (!feof($fp)) {
                          $string .= fgets($fp, 128);
                      }
                  }
                  fclose($fp);
              }
              $string_encoding = mb_detect_encoding($string, &quot;UTF-8, ISO-8859-1, ISO-8859-15&quot;, true);
              $string_utf8 = mb_convert_encoding($string, &quot;UTF-8&quot;, $string_encoding);
              return htmlspecialchars($string_utf8, ENT_COMPAT, &quot;UTF-8&quot;, true);
          } else {
              return &quot;No whois server for this tld in list!&quot;;
          }
      } else {
          return &quot;Domain name isn't valid!&quot;;
      }
  }
  public function htmlInfo()
  {
      return nl2br($this-&gt;info());
  }
  public function getDomain()
  {
      return $this-&gt;domain;
  }
  public function getTLDs()
  {
      return $this-&gt;TLDs;
  }
  public function getSubDomain()
  {
      return $this-&gt;subDomain;
  }
  public function isAvailable()
  {
      $whois_string = $this-&gt;info();
      $not_found_string = '';
      if (isset($this-&gt;servers[$this-&gt;TLDs][1])) {
         $not_found_string = $this-&gt;servers[$this-&gt;TLDs][1];
      }
      $whois_string2 = @preg_replace('/' . $this-&gt;domain . '/', '', $whois_string);
      $whois_string = @preg_replace(&quot;/\s+/&quot;, ' ', $whois_string);
      $array = explode (&quot;:&quot;, $not_found_string);
      if ($array[0] == &quot;MAXCHARS&quot;) {
          if (strlen($whois_string2) &lt;= $array[1]) {
              return true;
          } else {
              return false;
          }
      } else {
          if (preg_match(&quot;/&quot; . $not_found_string . &quot;/i&quot;, $whois_string)) {
              return true;
          } else {
              return false;
          }
      }
  }
  public function isValid()
  {
      if (
          isset($this-&gt;servers[$this-&gt;TLDs][0])
          &amp;&amp; strlen($this-&gt;servers[$this-&gt;TLDs][0]) &gt; 6
      )
      {
          $tmp_domain = strtolower($this-&gt;subDomain);
          if (
              preg_match(&quot;/^[a-z0-9\-]{3,}$/&quot;, $tmp_domain)
              &amp;&amp; !preg_match(&quot;/^-|-$/&quot;, $tmp_domain) //&amp;&amp; !preg_match(&quot;/--/&quot;, $tmp_domain)
          )
          {
              return true;
          }
      }
      return false;
  }
  }
  ?&gt;
  </code></pre>