我是 PHP 新手,需要一些帮助来完成我的脚本。我有一个可以从域名中获取所有单词的 PHP 脚本。我需要脚本能够找到最有可能是域名关键字的单词。
这是我的脚本:
<?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 ) );
?>
代码输出如下:
域名:where-amigoing.togoto.com 领域词:whereamigoingtogoto 域名后缀:.com 数组 ( [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] =>去 [34] => 去 [36] => o [37] => oi [40] => 在 [42] => n [45] => gt [47] => t [48] => 到 [ 49] => tog [50] => togo [56] => 得到 [59] => ot
我想取数组,找到没有任何单词重叠的单词组合,以确定域名关键字。
有人知道怎么做吗?我知道我需要遍历这些单词并对照原始域检查它们,但这似乎有点超出我的想象。