English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP similar_text() Function Usage and Example

    PHP String String Functions Manual

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

Syntax

int similar_text ( string $first , string $second [, float &$percent ] )

Definition and Usage

Used to calculate the similarity between two strings

Return Value

 Returns the number of matching characters in the two strings.

Parameter

NumberParameters and Description
1

first (required)

Information about the first string

2

second (required)

Information about the second string

3

percent (optional)

By passing the third parameter by reference, similar_text() will calculate the similarity percentage.

Online Example

Try the following example, calculate www.oldtoolbag.com and oldtoolbag.com The similarity is:

<?php
   //Calculate www.oldtoolbag.com and oldtoolbag.com The similarity
   echo similar_text("www.oldtoolbag.com,"oldtoolbag.com);
?>
Test and See‹/›

Output Result

9

Try the following example, calculate www.oldtoolbag.com and oldtoolbag.com The percentage similarity of these two strings is:

<?php
   //Calculate www.oldtoolbag.com and oldtoolbag.com This two strings have a percentage similarity of
   similar_text("www.oldtoolbag.com,"oldtoolbag.com,$percent);
   echo $percent;
?>
Test and See‹/›

Output Result

81.818181818182

PHP String String Functions Manual