Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. <?php
  2.  
  3. $search = 'griffyn';
  4. $truth = 'griffin';
  5.  
  6. $same = 0;
  7. $different = strlen($truth);
  8.  
  9. $matching = '';
  10.  
  11. for($i = 0; $i < strlen($truth); $i++)
  12. {
  13.   if(isset($search[$i]) && $search[$i] == $truth[$i])
  14.   {
  15.     $same++;
  16.     $different--;
  17.     continue;
  18.   }
  19.   else
  20.   {
  21.     $matching = substr($truth, 0, $same);
  22.     break;
  23.   }
  24. }
  25.  
  26. echo 'Different: ' . $different . '<br>';
  27. echo 'Same: ' . $same . '<br>';
  28. echo 'Matching Part: ' . $matching . '<br>';
  29.  
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement