I would like to know if there is a possibility to check in SQL via PHP, if there is a title that contains more than 3 letters identical from a news headline.
the website receives headlines from the world's leading news sites via RSS. And I want to filter out that there will be a difference of several hours / day a similar title (containing 3 letters or more).
<?php
header('Content-Type: text/html; charset=utf-8');
$value = 'ABC ACB JAJAM HGOGLA';
if(dubtitle($value) === true) exit; // dubtitle($value) = true
function dubtitle($value){
$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
//Output any connection error
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
$start = strtotime("-1 DAY");
$end = time();
$results = $mysqli->prepare("SELECT id, title, time FROM table WHERE (time BETWEEN '".$start."' AND '".$end."')");
$mysqli->set_charset("utf8");
$results->bind_result($id, $title, $time);
$found = false;
while($results->fetch()){
$parts = explode(" ", $title); // $title = 'ABC ACB ABGF JAJA';
foreach ($parts as $part){
if(mb_strpos(trim($part), trim($value)) !== false){
$count++;
}
if($count >= 3){
$found = 'yes';
break;
}
}
}
if($found === 'yes'){
return true;
}else{
return false;
}
}
in my exmaple $value = 'ABC ACB JAJA HGOGLA' / $title = 'ABC ACB ABGF JAJAm' we can find 3 words of $value in $title (ABC , ACB , JAJA) so the function will return true.