Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get words that are matching in second string in PHP

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is string

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

Thanks

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading