2010-03-01 84 views
1

我要为下面的示例代码....正则表达式在PHP查找单词

例如....

$words = "The sculpture was selected during a design competition. After 
    Kapoor's design was chosen, numerous technological concerns regarding 
    the design's construction and assembly arose, in addition to concerns 
    regarding the sculpture's upkeep and maintenance. Various experts were 
    consulted, some of whom believed the design could not be implemented. 
    Eventually, a feasible method was found, but the sculpture's construction 
    fell behind schedule. It was unveiled in an incomplete form during the 
    Millennium Park grand opening celebration in 2004, before being concealed 
    again while it was completed. Cloud Gate was formally dedicated on 
    May 15, 2006, and has since gained considerable popularity, both 
    domestically and internationally."; 

只是我搜索的词是“设计一些大公园”

我需要搜索词的前30个单词。像谷歌搜索结果页面.....

感谢

+0

因此,你想在“设计”,“一些”,“大”或“公园”的任何一个*之后获取'$ words'中的前30个单词?所以你想要“设计比赛。选择卡普尔的设计之后[剪辑23个单词]”? – 2010-03-01 09:17:33

回答

1

使用preg_match_all,最后一个参数让你根据所提供的模式的结果。你可以提供一个常量字符串而不是正则表达式模式!

2

你可能会感兴趣Sphinx API,如果你想像真正的搜索引擎那样做。

+0

如果你想使用搜索引擎,然后尝试ZEND框架! – 2010-03-01 09:30:04