<?php
// (C) Copyright 2008 Collins Research, Inc.

// Free for commercial or personal use
// NO WARRANTIES WHATSOVER

// Spell check domain names and find keywords of domain names
// Author: Roger Collins
// Email: roger-nospam@rogercollins.com
// (remove the -nospam part unless you're spamming)

// 5/8/08 Version 0.01

$ps_cfg pspell_config_create("en");
pspell_config_ignore($ps_cfg1);
$ps_link pspell_new_config($ps_cfg);

$ps_cfg_rt pspell_config_create("en");
pspell_config_runtogether($ps_cfg_rttrue);
pspell_config_ignore($ps_cfg1);
$ps_link_rt pspell_new_config($ps_cfg_rt);

function 
spellcheck($name)
{
    global 
$ps_link_rt;
    return 
pspell_check($ps_link_rt$name) ? 0;
}

function 
keywords($name)
{
    global 
$ps_link;

    
$n strlen($name);

    if (
$n <= 1) {
        
// case 0 or 1 char string

        
if ($name == 'a' or $name == 'i') {
            return 
$name;
        }
        else {
            return 
'';
        }
    }
    elseif (
pspell_check($ps_link$name)) {
        
// case 1 word

        
return $name;
    }
    elseif (
$n <= 3) {
        
// case short name with no words

        
return '';
    }
    else {
        
// case 0 or multiple words at least 3 chars

        
$ans '';
        for (
$i $n 2$i 0; --$i) {
            
$lh substr($name0$i);
            if (
pspell_check($ps_link$lh)) {
                
$rh substr($name$i$n);
                
$kw keywords($rh);
                if (
$kw == '')
                    continue;
                else {
                    
$tmp_ans $lh ' ' $kw;
                    if (
strlen($tmp_ans) < strlen($ans) or $ans == '') {
                        
// Best answer so far (least number of words)
                        
$ans $tmp_ans;
                    }
                }
            }
        }
        return 
$ans;
    }
}
?>