How to filter similar string in php? -


this example:

$string1 = "i love php coding , want help"; $string2 = "i java coding , other people" ; $output = anyfunction($string1, $string2); 

and want output = i coding , help

is there built-in function in php task?

try this:-

<?php $string1 = "i love php coding , want help"; $string2 = "i java coding , other people" ;   function getcommoncharacter($str1,$str2,$case_sensitive = false)   {     $ary1 = explode(' ',$str1);     $ary2 = explode(' ',$str2);      if ($case_sensitive)     {       $ary1 = array_map('strtolower',$ary1);       $ary2 = array_map('strtolower',$ary2);     }      echo (implode(' ',array_intersect($ary1,$ary2)));   }   getcommoncharacter($string1,$string2,$case_sensitive = false);   ?> 

output:-http://prntscr.com/746ewy

note:- case sensitivity taken false match lower or uppercase well. , can change see other results.thanks.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -