Home > database >  Get words that are matching in second string in PHP
Get words that are matching in second string in PHP

Time:12-22

I have two strings

$str_original='This is first string';
$user_string='This is user string';

i want to get all the words that are matching with str_original string

Required output:

This is string

I can get this results using loop but is there any faster way to achieve this result using any function.

Thanks

CodePudding user response:

This problem has already been answered here: Php compare strings and return common values

You can just replace the string with the variables while calling the function common from the above solved answer:

Replace:

echo common('Product Name - Blue','Blue Green Pink Black Orange');

With:

echo common($str_original,$user_string);

where you can make str_original and user_string dynamic.

  •  Tags:  
  • php
  • Related