Compare 2 set of strings and get percentage of Match

/ Published in: PHP
Save to your folder(s)

Get percentage of how much 2 strings matches with each other. Good for comparing things that doesn't have to be an exact match to fit.

Copy this code and paste it in your HTML
  1. $str1 = ereg_replace("[^A-Za-z0-9]", "", $str1);
  2. $str2 = ereg_replace("[^A-Za-z0-9]", "", $str2);
  3. similar_text($str1, $str2, $percent);
  4. //$percent = how much they match!

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.