[ create a new paste ] login | about

Link: http://codepad.org/guTbyYru    [ raw code | output | fork ]

PHP, pasted on Jun 6:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php 
function getIntersection ($str1,$str2)
{
    //get the min length of str1 & str2
    $l = strlen($str1) <= strlen($str2)? strlen($str1):strlen($str2);
    $intersection = "";
    //substring length
    $i = 0;
    while($i < $l && (substr($str1,0,$i) == substr($str2,0,$i) ))
    {
        $i++;
    }
    return substr($str1,0,$i-1);
}
$a = 'Metric Bob Foundation A5, Lined,sdf Pink &amp; Orange';
$b = 'Metric Bob Foundation A5, Lined, Navy &amp; Green';
echo getIntersection ($a, $b);


Output:
1
Metric Bob Foundation A5, Lined,


Create a new paste based on this one


Comments: