3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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); $relative = ($result / $total_words) * 100; if($relative > 50) { echo $relative. '% related to your query (Total words: '.$total_words.', Words found: '.$result.')'; } else { echo 'Could not find anything related'; }
Output for 4.3.0 - 7.1.0
66.666666666667% related to your query (Total words: 3, Words found: 2)