3v4l.org

run code in 300+ PHP versions simultaneously
<?php function substr_count_array( $haystack, $needle ) { $count = 0; foreach ($needle as $substring) { $count += substr_count( $haystack, $substring); } return $count; } $str = 'The fox jumped over the table and ate a frog'; $search = 'fox ate apple'; $words = explode(' ', $search); $result = substr_count_array($str, $words); $total_words = sizeof($words); if(($result / $total_words) * 100 > 50) { echo 'Related to your query (Total words: '.$words.', Words found: '.$result.')'; } else { echo 'Could not find anything related'; }

preferences:
31.89 ms | 402 KiB | 5 Q