I use a piece of code as follows:
$list = array(
"This" => "9",
"great" => "10",
"God Father" => "11",
"Tony Montana" => "12",
"Ronaldo" => "13",
"Al Pacino" => "14",
"Humans" => "15",
"Play" => "16"
);
$post = Array ( [title] => "This is a test - That game is awesome (Cristiano Ronaldo is a great Soccer Player).",
"This is a not a test - That game is OK (Maradonal was a great Soccer Player)."
);
foreach ($post as $keyword) {
foreach ($list as $word=>$num) {
$sim_chars = similar_text($keyword, $word);
if ($sim_chars/strlen($keyword) > .8 || $sim_chars/strlen($word) > .8) {
$all_key_values[] = $num;
$all_keys[] = $word;
}
elseif (stripos($keyword, $word) !== false || strpos($word, $keyword) !== false) {
$sll_key_values[] = $num;
$all_keys[] = $word;
}
}
}
The code works well to pass an array like $post = array ('Humans', 'Tony Montana', 'Tech', 'Creative');
to match the keywords with another list of keywords in a different array. But I want to pass an array with $post
like structure (in the code) to find the keywords from the post titles. So, my question is how can I split the $post
value (i.e. This is a test - That game is awesome (Cristiano Ronaldo is a great Soccer Player).
) into smaller words which are greater than 2 characters in length (i.e. This
, test
, That
, game
, awesome
, Cristiano
, Ronaldo
, great
, Soccer
and Player
) and removing the special characters before passing the $post
into the foreach loops. Thanks a lot for helping me on this problem.