title: Finding word combinations on domain names
body: <p>I am a PHP novice and need some help finishing my script. I have a PHP script that can take all of the words from a domain name. I need the script to be able to find the most likely words that are the domain name's keywords.</p>
  
  <p>Here is my script:</p>
  
  <pre><code>&lt;?php
  
  $domain = trim(htmlspecialchars('where-amigoing.togoto.com'));
  preg_match('/(.*?)((\.co)?.[a-z]{2,4})$/i', $domain, $m);
  $ext = isset($m[2]) ? $m[2]: '';
  
  $replace = array($ext,'-','.');
  $domainWords = str_replace($replace,'',$domain);
  
  //Find Word in Dictionary
  function pspell_icheck($dictionary_link, $word) {
    return ( pspell_check($dictionary_link, $word) ||
      strtolower(reset(pspell_suggest($dictionary_link, $word))) == strtolower($word) );
  }
  
  //Find Words
  function getwords( $string ) {
      if( strpos($string,"xn--") !== false ) {
          return false;
      }
      $pspell = pspell_new( 'en' );
      $check = 0;
      $words = array();
      for( $j = 0; $j &lt; ( strlen( $string ) ); $j++ ) {
          for( $i = 0; $i &lt; strlen( $string ); $i++ ) {
              if( pspell_icheck( $pspell, substr( $string, $j, $i ) ) ) {
                  $check++;
                  $words[] = substr( $string, $j, $i );
              }
          }
      }
      $words = array_unique( $words );
      if( $check &gt; 0 ) {
          return $words;
      }
      return false;
  }
  
  echo 'domain name: '.$domain .'&lt;br&gt;';
  echo 'domain words: '.$domainWords .'&lt;br&gt;';
  echo 'domain extension: '.$ext .'&lt;br&gt;';
  print_r ( getWords( $domainWords ) );
  
  ?&gt;
  </code></pre>
  
  <p><strong>The code outputs this:</strong></p>
  
  <pre>
  domain name: where-amigoing.togoto.com
  
  domain words: whereamigoingtogoto
  
  domain extension: .com
  
  Array ( [0] => [1] => w [2] => where [4] => h [5] => he [6] => her [7] => here [9] => e [10] => er [11] => ere [13] => r [14] => re [15] => rea [16] => ream [19] => ea [21] => a [22] => am [23] => ami [24] => amigo [26] => m [27] => mi [28] => mig [30] => i [32] => g [33] => go [34] => going [36] => o [37] => oi [40] => in [42] => n [45] => gt [47] => t [48] => to [49] => tog [50] => togo [56] => got [59] => ot )
  </pre>
  
  <p>I want to take the array and find the word combinations without any word overlapping, to determine the domain name keywords.</p>
  
  <p>Anyone know how to do this? I know I need to loop through the words and check them against the original domain, but this seems a little over my head.</p>