我正在寻找一个php库,可以使用像“happyeaster”或“buyaboat”这样的字符串并返回单个单词 - “开心”和“复活节”或“买”“一艘”“船”。有没有人知道现有的图书馆或已经建成的可以下载或购买的东西?使用PHP查找没有空格的字符串中的单词
0
A
回答
0
我结束了这个脚本http://squarecog.wordpress.com/2008/10/19/splitting-words-joined-into-a-single-string/并在PHP中重做它。我也接受最少量文字的第一个解决方案。
+3
既然你已经要求一个PHP库,你已经回答了你的问题,我相信这是公平的发布代码。 –
0
如果不先告诉它,php将无法知道您正在查找哪些词。
所以你可能需要详细阐述一下你试图获得有价值的答案。
你也许可以使用reg ex并且有一个单词数组来查找,或者substr。
例如,如何将PHP知道你想要的单词快乐和复活节,而不是东方也发现在该字符串?
0
像你需要一个全文搜索库的声音。试试Lucene和Zend Lucene库。希望这个帮助。
0
<?php
function binary_search($elem, $array) {
$top = sizeof($array) -1;
$bot = 0;
while($top >= $bot) {
$p = floor(($top + $bot)/2);
if ($array[$p] < $elem)
$bot = $p + 1;
elseif ($array[$p] > $elem)
$top = $p - 1;
else
return TRUE;
}
return FALSE;
}
$handle = @fopen("/usr/share/dict/words", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
$words[] = trim($buffer);
}
fclose($handle);
}
sort($words);
function getmultiplewords($word1, $word2, &$dict){
if (strlen($word1)==0) return;
if (binary_search($word1, $dict) && binary_search($word2, $dict)) {
echo $word2 . "/" . $word1. "\n";
}
$word2 = $word2 . substr($word1,0,1);
$word1 = substr($word1,1);
getmultiplewords($word1, $word2, $dict);
}
getmultiplewords("cartalk","", $words);
getmultiplewords("superman","", $words);
?>
下面是一个简单的解决方案,它查找2分词的单词。
它的工作原理与的/ usr /共享/字典/单词文件Linux的,否则你将不得不自己下载此文件:
http://www.freebsd.org/cgi/cvsweb.cgi/src/share/dict/web2?rev=1.12;content-type=text%2Fplain
如果你想ň wordsplitting可为合理大小的单词做:)也只是让我知道,我会研究它。
相关问题
- 1. 查找字符串中没有空格的单词PHP
- 2. PHP-解析字符串中没有空格的单词?
- 3. 如何在PHP中使用无空格字符串查找单词?
- 4. 查找字符串中的单词词
- 5. 使用preg_match查找URL中的单词(或字符串不包含空格)
- 6. 查找字符串中的单词
- 7. 查找没有空字符串的行
- 8. 查找字符串中的空格
- 9. 使用字典查找python中的空格固定单词?
- 10. 字符串查找单词的Javascript
- 11. PHP,如何查找单词是否在我的字符串中?
- 12. 使用Oracle SQL查找字符串中最长的单词
- 13. C程序使用strtok查找字符串中的单个词
- 14. 使用Javascript来查找字符串中最常见的单词?
- 15. 使用strpos查找字符串中的单词
- 16. 如何在字符串单词应用程序中的简单的mysql/php单词中查找单词匹配?
- 17. PHP - 查找字符串中特定字符长度的最常用单词。
- 18. 查找单元格中的字符串
- 19. 如何从python中没有空格的字符串中提取单词?
- 20. 没有空格和特殊字符的字符串中的词频?
- 21. PHP没有空格的hashtags字符串没有被分成hashtags
- 22. 如何在PHP中查找字符串的第二个空格?
- 23. 如何查找字符串中所有最长的单词?
- 24. 在字符串中查找所有想要的单词
- 25. indexOf在字符串中查找所有出现的单词
- 26. 查找字符串中特定单词字符的索引号
- 27. 使用JavaScript查找字符串中的空格数
- 28. 如何查找只有大写字母的单词(字符串)?
- 29. 查找单词和分割字符串
- 30. 查找字符串中的单词的简单代码
你只希望它为2个单词工作或为* n *单词工作吗? – abcde123483
如果“购买”“ab”“燕麦”回来了怎么办? –
听起来像这个库会返回很多错误:D takeaway = take way ||带走 ? – luso