PHP similar_text() Function

Definition

The similar_text() function calculates the similarity between two strings.

Syntax

PHP similar_text() Function has the following syntax. similar_text(string1,string2,percent)

Parameter

ParameterIs Required Description
string1Required. First string to be compared
string2Required. Second string to be compared
percentOptional. Variable name for storing the similarity in percent

Return

PHP similar_text() Function returns the number of matching characters of two strings.

Example

Calculate the similarity between two strings and return the matching characters:


<?php
echo similar_text("Hello World","Hello from java2s.com");
?>

The code above generates the following result.

Example 2

Calculate the similarity between two strings in percent:


<?php
similar_text("Hello World","Hello from java2s.com",$percent);
echo $percent;
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions