Computer >> Computer tutorials >  >> Programming >> PHP

similar_text() function in PHP


The similar_text() function is used to calculate the similarity between two strings.

Syntax

similar_text(str1, str2, percent)

Parameters

  • str1 − The first thing to be compared

  • str2 − The second string to be compared

  • percent − Specifies a variable name for storing the similarity in percent.

Return

The similar_text() function returns the number of matching characters of two strings.

Example

The following is an example −

<?php
   $res = similar_text("mobile", "mobility", $percent);
   echo "Count of similar characters : $res\n";
?>

Output

The following is the output −

Count of similar characters : 5

Example

Let us see another example that checks for two empty strings −

<?php
   similar_text("", "", $res);
   echo $res;
?>

Output

The following is the output −

0