我无法编写将检查新闻中关键字的代码如果它将存在来自5个关键字的2个匹配项。脚本会在新数据库中插入此帖子。
这是我的代码,但只检查一个关键字,如果存在,则将此消息插入数据库。
$sq = 'SELECT Keyword FROM keyword';
$receivekey = mysqli_query($conn,$sq);
if(! $receivekey )
{
die('Could not load data: ' . mysql_error());
}
while($row = mysqli_fetch_array($receivekey)){
$itemkey[] = $row['Keyword'];
}
//echo '<br>'.$itemkey[1];
foreach( $itemkey as $newkey => $value){
echo '<br>'.$value;
//print_r($value);
}
mysqli_close($conn);
//select the correct xml for social media
//read xml and check for preference
//$content = simeplexml_load_file('facebook.xml');
$xml = simplexml_load_file('facebook.xml');
foreach($xml->Tue14Apr2015 as $entry);
foreach($entry->post as $new){
$new = strtolower($new);
if (is_array($itemkey))
{
foreach($itemkey as $e => $ne){
$pos = strpos($new, $ne);
if ($pos == true){
echo '<br>'.$new;
答案 0 :(得分:0)
尝试使用substr_count
,如下所示:
$occurrence = 0;
foreach($itemkey as $key){
$occurrence += substr_count($news, $key);
}
if($occurrence >= 2) {
// Insert news in database here
}
这会增加找到的每个关键字的出现次数。