Example 1 — Compare Two Similar Words
Get the number of matching characters and the percent.
<?php
$matches = similar_text("World", "Word", $percent);
echo "Matches: ", $matches, PHP_EOL;
echo "Percent: ", round($percent, 2), PHP_EOL; How It Works
- Pass two strings. They are almost the same word.
- Add a variable.
$percentis filled by reference. - Read the count. Four characters match.
- Round the percent.
round()keeps the output short.

