2010-03-01 62 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