用于查找/识别域名中的单词的PHP脚本

时间:2012-01-23 01:14:15

标签: php dns words names

我正在寻找能够识别域名中的单词的PHP代码/脚本。

例如,当用户查询域名snapnames.com时 - 此脚本将显示SnapNames.com(识别此域中的2个字:Snap Names)

希望有人可以提供帮助

由于

1 个答案:

答案 0 :(得分:2)

我担心没有完美答案......正如阿诺德所说,像“expertsexbhange.com”这样的域名可以评估为“Expert Sex Change.com”以及“Experts Exchange.com”。

不仅如此,这种功能对内存和处理能力也相当密集。您需要拥有巨大的文件才能识别所有单词等。很高兴知道您为什么需要这样做,以便尝试找到不同的解决方案。

如果您有某种显示网站信息的服务,则显示“Snapnames.com”是完全可以接受的。没有必要把它或其他类似的资本化。

然而,如果你对这种行为感到沮丧并且已经确定,即使它不是100%准确,而且在你的服务器上相当激烈......

首先需要找到一种检查字符串是否为单词的方法。这是一个完全独立的问题,有一个完全合理的答案。您需要单独询问,看看是否可以找到PHP的字典库。

基本上,向后遍历你的字符串直到它成为一个单词,从字符串中删除该单词,然后重复。例如:

expertsexchange.com,您可以这样检查:

第一个{}是您的单词列表foubnd。 第一个“”是你要检查的所有字母 最后一个“”是您正在检查的当前字母子集

{} "expertsexchange" "expertsexchange" <-- not a word
{} "expertsexchange" "expertsexchang" <-- not a word
{} "expertsexchange" "expertsexchan" <-- not a word
{} "expertsexchange" "expertsexcha" <-- not a word
{} "expertsexchange" "expertsexch" <-- not a word
{} "expertsexchange" "expertsexc" <-- not a word
{} "expertsexchange" "expertsex" <-- not a word
{} "expertsexchange" "expertse" <-- not a word
{} "expertsexchange" "experts" <-- WORD! Add it to our list of words
{"experts"} "exchange" "exchange" <-- WORD! Add it to our list of words
{"experts", "exchange"} "" "" <-- No more letters to check, we have found all of our words.

让我们尝试一个不同的例子......

hellotherewittlekitty。这有一个“字”(“wittle”),字典无法识别。不幸的是,这就是算法如何处理:

{} "hellotherewittlekitty" "hellotherewittlekitty" <-- not a word
{} "hellotherewittlekitty" "hellotherewittlekitt" <-- not a word
{} "hellotherewittlekitty" "hellotherewittlekit" <-- not a word
{} "hellotherewittlekitty" "hellotherewittleki" <-- not a word
{} "hellotherewittlekitty" "hellotherewittlek" <-- not a word
{} "hellotherewittlekitty" "hellotherewittle" <-- not a word
{} "hellotherewittlekitty" "hellotherewittl" <-- not a word
{} "hellotherewittlekitty" "hellotherewitt" <-- not a word
{} "hellotherewittlekitty" "hellotherewit" <-- not a word
{} "hellotherewittlekitty" "hellotherewi" <-- not a word
{} "hellotherewittlekitty" "hellotherew" <-- not a word
{} "hellotherewittlekitty" "hellothere" <-- not a word
{} "hellotherewittlekitty" "hellother" <-- not a word
{} "hellotherewittlekitty" "hellothe" <-- not a word
{} "hellotherewittlekitty" "helloth" <-- not a word
{} "hellotherewittlekitty" "hellot" <-- not a word
{} "hellotherewittlekitty" "hello" <-- WORD! add it to list, and remove form main string!
{"hello"} "therewittlekitty" "therewittlekitty" <-- not a word
{"hello"} "therewittlekitty" "therewittlekitt" <-- not a word
{"hello"} "therewittlekitty" "therewittlekit" <-- not a word
{"hello"} "therewittlekitty" "therewittleki" <-- not a word
{"hello"} "therewittlekitty" "therewittlek" <-- not a word
{"hello"} "therewittlekitty" "therewittle" <-- not a word
{"hello"} "therewittlekitty" "therewittl" <-- not a word
{"hello"} "therewittlekitty" "therewitt" <-- not a word
{"hello"} "therewittlekitty" "therewit" <-- not a word
{"hello"} "therewittlekitty" "therew" <-- not a word
{"hello"} "therewittlekitty" "there" <-- WORD! add it to list, and remove from main string
{"hello", "there"} "wittlekitty" "wittlekitty" <-- not a word
{"hello", "there"} "wittlekitty" "wittlekitt" <-- not a word
{"hello", "there"} "wittlekitty" "wittlekit" <-- not a word
{"hello", "there"} "wittlekitty" "wittleki" <-- not a word
{"hello", "there"} "wittlekitty" "wittlek" <-- not a word
{"hello", "there"} "wittlekitty" "wittle" <-- not a word (even though humans read it as one)
{"hello", "there"} "wittlekitty" "wittl" <-- not a word
{"hello", "there"} "wittlekitty" "witt" <-- WORD! add to dictionary and remove from string
{"hello", "there", "witt"} "lekitty" "lekitty" <-- not a word
{"hello", "there", "witt"} "lekitty" "lekitt" <-- not a word
{"hello", "there", "witt"} "lekitty" "lekit" <-- not a word
{"hello", "there", "witt"} "lekitty" "leki" <-- WORD! (biology, wikipedia)
{"hello", "there", "witt", "leki"} "tty" "tty" <-- not a word
{"hello", "there", "witt", "leki"} "tty" "tt" <-- not a word
{"hello", "there", "witt", "leki"} "tty" "t" <-- not a word
{"hello", "there", "witt", "leki"} "tty" "" <-- No more letters, add it to the list!
{"hello", "there", "witt", "leki", "tty"} "" ""

因此,hellotherewittlekitty会以HelloThereWittLekiTty的形式出现,这比将它全部保持为小写更糟糕。

还有更多的算法在你的CPU上比这更加密集,并且需要更多的数据,这可能会为你提供更高的准确性。但总而言之,对于所有工作而言,只获得30%的准确性是不值得的。特别是因为当算法失败时,它会破坏你的话语。这意味着添加此功能会使60%的网站毁了。