【发布时间】:2012-01-27 09:25:07
【问题描述】:
我有一个值这样的变量:
$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锚。 -
请在php中显示代码?
标签: php arrays string preg-match str-replace