title: First segment of a intersection between two string
body: <p>I'm trying to get the first segment of a intersection between two strings in PHP. Something like that:</p>
  
  <pre><code>$a = 'Metric Bob Foundation A5, Lined, Pink &amp;amp; Orange';
  $b = 'Metric Bob Foundation A5, Lined, Navy &amp;amp; Green';
  echo SOME_FUNCTION($a, $b);
  
  // Expected output: 'Metric Bob Foundation A5, Lined, '
  </code></pre>
  
  <p>Could anyone help me with the SOME_FUNCTION.</p>
  
  <p>I've used this one here:</p>
  
  <pre><code>function string_intersect($string1, $string2)
  {
      $array1 = $array2 = array();
  
      for($i = 0, $j = 0, $s1_len = strlen($string1), $s2_len = strlen($string2);($i &lt; $s1_len) || ($j &lt; $s2_len); $i++, $j++) {
          if($i &lt; $s1_len) {
              $array1[] = $string1[$i];
          }
          if($j &lt; $s2_len) {
              $array2[] = $string2[$j];
          }
      }
  
      return implode('', array_intersect($array1, $array2));
  }
  </code></pre>
  
  <p>But it returns: 
  // Metric Bob Foundation A5, Lined, in &amp; rane</p>
  
  <p>Which is not quite right. As I said, I want just the firs segment.</p>
  
  <p>Thanks in advance.</p>