Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php count matching words in two strings

$string1 = 'The dog and cat love each other';
$string2 = 'the dog pooped in the yard';
$arr1 = explode(" ",$string1 );
$arr2 = explode(" ",$string2 );
$result = array_intersect($arr1 , $arr2 ); //matched elements
$num = count($result); //number of matches
Comment

PREVIOUS NEXT
Code Example
Php :: php replace first occurrence in string 
Php :: laravel eloquent select one column in array 
Php :: artisan make command 
Php :: exec output php 
Php :: Fatal error: Exception thrown without a stack frame in Unknown on line php 
Php :: symfony see all make command 
Php :: how to remove Website field from comments 
Php :: string remove last two characters php 
Php :: php binary to base64 
Php :: php artisan tinker send email 
Php :: random string in php 
Php :: Determining if input is present in Laravel 
Php :: laravel observer events 
Php :: HTML5 Date Valu In PHP 
Php :: migrate specific file in laravel 
Php :: wp_enqueue_script 
Php :: codeigniter 4 limit query 
Php :: Laravel Excel numbers formatted as text still appearing as number 
Php :: str_ireplace 
Php :: spl_autoload_register 
Php :: pdo close connection 
Php :: 0 
Php :: laravel scss 
Php :: how to use join in laravel 5.4 
Php :: wherejsoncontains laravel 
Php :: yii2 dataprovider to model 
Php :: laravel wherein example 
Php :: settimezone in php 
Php :: php check if text is blank 
Php :: get ip address of client php 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =