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.
Here is my script:
<?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 < ( strlen( $string ) ); $j++ ) {
for( $i = 0; $i < strlen( $string ); $i++ ) {
if( pspell_icheck( $pspell, substr( $string, $j, $i ) ) ) {
$check++;
$words[] = substr( $string, $j, $i );
}
}
}
$words = array_unique( $words );
if( $check > 0 ) {
return $words;
}
return false;
}
echo 'domain name: '.$domain .'<br>';
echo 'domain words: '.$domainWords .'<br>';
echo 'domain extension: '.$ext .'<br>';
print_r ( getWords( $domainWords ) );
?>
The code outputs this:
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 )
I want to take the array and find the word combinations without any word overlapping, to determine the domain name keywords.
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.