Check Strings has matching keywords in php

I have two inputs or strings which will be sent to PHP function.

Example1:

$string1 = "these is a good tutorial for the learning";
$string2 = "good tutorial are available in website";

Example2:

$string1 = "learning is a good habit";
$string2 = "good habit to refer website";

My need is to check if the two string has the same keywords(eg: good tutorial, good habit) or not

if($string1 contains matching keyword with $string2 ){
     echo true;
}

Any help will be much appreciated. Thanks in advance!

<?php
$input = "good tutorial";
$string1 = "these is a good tutorial for the learning";
$string2 = "good tutorial are available in website";

if(preg_match("/".$input."/", $string1) && preg_match("/".$input."/", $string2))
    echo 'true';

Something like this?

Try this

<?php
$string1 = "these is a good tutorial for the learning";
$string2 = "good tutorial are available in website";

$string1 = explode(' ',$string1);
$string2 = explode(' ',$string2);

$match = '';

foreach($string1 as $keyword){
       if(in_array($keyword,$string2)){
                  $match.=' '.$keyword;
        }
 }
 echo $match;
?>

If you are trying to find common words from both strings you could try the following approach:

<?php
$string1 = "these is a good tutorial for the learning";
$string2 = "good tutorial are available in website";

$words1  = explode(' ', $string1);
$words2  = explode(' ', $string2);

$strings_in_common = array_intersect($words1, $words2);

var_dump($strings_in_common);

Output:

array (size=2)
  3 => string 'good' (length=4)
  4 => string 'tutorial' (length=8)

If you are searching strings and are checking that they contain certain sub-strings/words:

<?php
function contains_all_words_in_strings(array $words, array $strings) {
    foreach($strings as $string) {
        if (array_diff($words, explode(' ', $string)))
            return false;
    }

    return true;
}


$string1 = "these is a good tutorial for the learning";
$string2 = "good tutorial are available in website";

$words = array('good', 'tutorial');
var_dump(contains_all_words_in_strings($words, array($string1, $string2)));

$words = array('good', 'foo');
var_dump(contains_all_words_in_strings($words, array($string1, $string2)));

Output:

boolean true
boolean false

(Of course these strings have simple punctuation. They most likely will require some pre-processing/normalising.)