我有一個大字符串,超過1000個單詞。我需要的是找到某個單詞,然後將一些單詞包含在變量中。查找字符串中的某個單詞,然後環繞它
$in = 'This is a very long sentence, what I need is to find the word "phone" in this sentence, and after that, to wrap some words around it';
如何實現這一點:
$out = 'find the word "phone" in this sentence';
所以,你可以看到,當我找到單詞「手機」,我想這個詞的左向右&擴大。 一個真實的例子是,當您在google上查詢標題結果時,您會從網頁獲取一些內容,並且查詢以粗體顯示。
您的匹配有多模糊?精確匹配,還是與詞幹和這樣的規範化?你有搜索查詢的位置數據嗎? –
請確定一個*詞*是什麼。 – hakre