我有關鍵字短語abc,xyz,pqr,mno等。文本 - 「此文本包含abc和mno」,想要查找文本是否包含keyphrase字符串。 我正在尋找高效的解決方案。請在下面找到我目前的代碼。從文本中查找多個關鍵短語
<?php
$content = " this text contains keyphrases abc and mno ";
$tags = array(array('key_phrase'=>'abc'),array('key_phrase'=>'pqr'),array('key_phrase'=>'mno'));
foreach($tags as $tag){
$matches = array();
preg_match("/".$tag['key_phrase']."/", $content, $matches);
if(!empty($matches)){
echo "key_phrase present ".$tag['key_phrase'];
}
}
?>
strpos效率更高,資源消耗更少。 –
此問題屬於[代碼評論](http://codereview.stackexchange.com/) –
@ transporter_room_3 - http://codereview.stackexchange.com/questions/127025/find-multiple-keyphrases-from-a-text –