PHP similar text

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : similar_text() function

Description

The similar_text() function is used to calculate the number of similar characters between two strings. 
The similar_text() function can also calculate the similarity of the strings in percent.

Version

(PHP 4 and above)

Syntax

similar_text(first_string, second_string, npercent) 

Parameter

Name

Description

Required /
Optional

Type

first_string

The first input string.

Required

String

second_string

The second input string.

Required

String

npercent

Variable to store the percentage of similarity between the input strings.

Optional

Integer

Return value

Returns the number of matching chars in both strings.

Value Type : Integer

Example :

  1. echo "Comparing strings : 'Good Morning' and 'Good Evening'".'
    ';  

  2. echo 'No of similar characters : '.similar_text('Good Morning', 'Good Evening').'
    ';  

  3. similar_text('Good Morning', 'Good Evening', $similar_percent);  

  4. echo 'Similarity between two strings in  percentage : '. $similar_percent;  

  5. ?>  

Output :

Comparing strings : 'Good Morning' and 'Good Evening'
No of similar characters : 9
Similarity between two strings in percentage : 75