Home / Core PHP / How to get the common sub string in two string?

How to get the common sub string in two string?

Select Code
<?php
function retriveCalc($str1,$str2){
    $arr1=array();
    for($i=0;strlen($str1)>$i;$i++){
        $arr1[$i]=$str1[$i];
    }
    $arr2=array();
    for($i=0;strlen($str1)>$i;$i++){
        $arr2[$i]=$str1[$i];
    }
    $result = array_intersect($arr1,$arr2);
    return implode('',$result);
}
$str1='test';
$str2='testingindia';
echo retriveCalc($str1,$str2);
echo "<br>";
$str1='1234';
$str2='4254546234231';
echo retriveCalc($str1,$str2);
?>

About v.shakya

I am V.Shakya, Software Developer & Consultant I like to share my ideas, views and knowledge to all of you who come across my website. I am young, enthusiastic, highly motivated and self disciplined person. I completed my studies in Master of Computer Application and currently giving my technical expertise to one of the Big IT company. I have more than fifteen years of experience in vast field of Programming , Designing and Development of websites and various software's.

Check Also

PHP 5 Functions

The real power of PHP comes from its functions; it has more than 1000 built-in …

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.