Home >>PHP String Functions >PHP similar_text() Function

# PHP similar_text() Function

### PHP similar_text() Function

PHP similar_text() function is used to calculate the similarity between two given input strings. This function returns the number of matching characters in the both input strings as the output. This function is also used to calculate the similarity of the strings in percent.

Syntax:

`  similar_text(\$string1,\$string2,\$percent);`

### Parameter Values

Parameter Description
string1 This is a required parameter. This parameter contains the first string to be compared.
string2 This is a required parameter. This parameter contains the second string to be compared.
percent This is an optional parameter. This parameter contains a variable name for storing the similarity in percent.

Here is an example of similar_text() function in PHP:

```<html>
<body>

<?php
echo similar_text("PHP","PHPTPOINT");
?>

</body>
</html>
```
Output:
3

Here is an another example of similar_text() function in PHP:

```<html>
<body>

<?php
\$str1 ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
\$str2= "ABHI";
echo similar_text("\$str1","\$str2");
?>

</body>
</html>
```
Output:
4

Here is another example of similar_text() function in PHP using the \$percent parameter:

```<html>
<body>

<?php
similar_text("abcdefghijkl","asdfghjkl",\$percent);
echo \$percent;
?>

</body>
</html>
```
Output:
76.190476190476
{"ft_lang_label":"__label__en","ft_lang_prob":0.5283124,"math_prob":0.6134721,"size":1234,"snap":"2020-45-2020-50","text_gpt3_token_len":275,"char_repetition_ratio":0.18048781,"word_repetition_ratio":0.16875,"special_character_ratio":0.2471637,"punctuation_ratio":0.15763547,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9684971,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-11-24T18:01:15Z\",\"WARC-Record-ID\":\"<urn:uuid:23bb6ef5-64b1-4cdc-9210-1d8d9a7652e3>\",\"Content-Length\":\"76568\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:69e359bf-6ee6-433c-b398-4288f3e84eab>\",\"WARC-Concurrent-To\":\"<urn:uuid:5f67599c-59a9-435f-b4df-53f8d9010341>\",\"WARC-IP-Address\":\"172.67.134.245\",\"WARC-Target-URI\":\"https://www.phptpoint.com/php-string-similar_text-function/\",\"WARC-Payload-Digest\":\"sha1:2U463BQYXIHS3ZAYGFLKZPL3HHBQSTIH\",\"WARC-Block-Digest\":\"sha1:CWDH35F6N65HSEKD6WSMUILSCR7RT2YK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141176922.14_warc_CC-MAIN-20201124170142-20201124200142-00291.warc.gz\"}"}