PHP脚本查找/识别域名中的单词
我正在寻找一个可以识别域名中的单词的 php 代码/脚本。
例如,当用户查询域名snapnames.com时 - 该脚本将显示SnapNames.com(识别该域中的2个单词:Snap Names)
希望有人可以帮助
谢谢
I'm looking for a php code/script that can recognize words in the domain name.
For example when user query domain name snapnames.com - this script will display SnapNames.com (recognize 2 words in this domain: Snap Names)
Hope someone can help
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
恐怕没有完美的答案......正如阿诺德所说,像“expertsexbhange.com”这样的域名可以评估为“Expert Sex Change.com”以及“Experts Exchange.com”。
不仅如此,这样的功能对内存和处理能力的消耗相当大。您需要拥有巨大的文件才能识别所有单词等。很高兴知道为什么需要这个,以便尝试找到不同的解决方案。
如果您有某种显示网站信息的服务,那么显示“Snapnames.com”是完全可以接受的。没有必要将其大写或类似的东西。
但是,如果您一心一意地执行此行为,即使它不是 100% 准确,并且在您的服务器上相当严重……
您首先需要找到一种方法来检查字符串是否是单词。这是一个完全不同的问题,有着完全合理的答案。您需要单独询问,看看是否可以找到 PHP 的字典库。
基本上,向后迭代字符串,直到它变成一个单词,从字符串中删除该单词,然后重复。例如:
expertsexchange.com,您可以这样检查:
第一个 {} 是您找到的单词列表。
第一个“”是您要检查的所有字母
最后一个“”是您正在检查的当前字母子集
让我们尝试一个不同的示例...
hellotherewittlekitty。它有一个字典无法识别的“单词”(“wittle”)。不幸的是,这就是算法处理该问题的方式:
因此,hellotherewittlekitty 将显示为 HelloThereWittLekiTty,这比仅将其全部保留为小写更糟糕。
还有其他算法对 CPU 的消耗比这更大,并且需要更多数据,这可能会为您提供更高的准确性。但总而言之,对于所有的工作来说,仅获得 30% 的准确率是不值得的。特别是因为当算法失败时,它会毁掉你的话。这意味着添加此内容将使您 60% 的网站被毁。
I am afraid that there is no perfect answer... As, arnold said, domains like "expertsexbhange.com" can evaluate to "Expert Sex Change.com" as well as "Experts Exchange.com".
Not only this, but such a function would be rather intensive on memory and processing power. You would need to have HUGE files to be able to recognize all words, etc. It would be nice to know why you need this, so-as to try and find a different solution.
If you have some kind of service that displays information about a website, it is PERFECTLY acceptable to display "Snapnames.com". There is no need to capitalize it, or anything like that.
However, if you are hell bent and determined for this behavior, even if it isn't 100% accurate, and rather intense on your server...
You first will need to find a way to check if a string is a word. That is an entirely separate kind of question, with a perfectly reasonable answer. You would need to ask that separately, see if you can find a dictionary library for PHP.
Basically, iterate backwards through your string until it becomes a word, remove that word from the string, and repeat. For instance:
expertsexchange.com, you would check it as so:
The first {} is your list of words foubnd.
The first "" is all of the letters you have left to check
The last "" is the current subset of letters you are checking
Let's try a different example...
hellotherewittlekitty. This has a "word" ("wittle") which would not be recognized by a dictionary. Unfortunately, this is how the algorithm would handle that:
As such, hellotherewittlekitty would come out as HelloThereWittLekiTty, which would be even worse than just leaving it all lowercase.
There ARE further algorithms that are even more intensive on your CPU than this, and require more data, which could possibly provide for you a tad more accuracy. But all in all, for all the work, getting only 30% accuracy is just not worth it. Particularly because when the algorithm fails, it RUINs your words. That means adding this would make 60% of your websites ruined.