我有一個變量,像這樣的值:PHP的preg_match找到相關詞語
$sentence = "When it comes time to renew your auto insurance policy, be aware of how your carrier handles renewals";
而且我有以下值數組變量:
$searches = array('aware', 'aware of', 'be aware', 'be aware of');
$replaces = array('conscious', 'conscious of', 'remember', 'concentrate on');
我想找個只是「知道的',然後替換爲'專注於'。輸出象下面這樣:
當談到時間更新您的汽車保險政策,專注於運營商如何處理更新
只有
搜索「知道」作爲相關同義詞替換而不是別人。謝謝你的幫助。
好吧,這裏的新代碼:
$searches = array('aware of', 'be aware of', 'be aware', 'aware');
$replaces = array('conscious of', 'concentrate on', 'remember', 'conscious');
這是一個動態數組($searches
),希望大家理解......我們知道,以獲得最佳代名詞更換使用「」注意'取代'專心'。輸出象下面這樣:
當談到時間更新您的汽車保險政策,專注於運營商如何處理更新
排序字符串長度的搜索模式。並且可能在它們周圍使用'\ b'錨。 – mario 2012-01-27 09:27:11
請在PHP中顯示代碼? – 2012-01-27 09:41:04