PHP Similar Text()


The PHP function similar_text() is a simple algorithm for calculating the similarity between two strings. A string represents a sequence of characters, letters or words that are grouped together as a string of variable length. In practice, PHP similar-text() fulfills many different purposes for websites and can increase their functionality.

Background

The algorithm is based on an Oliver described method (a 1993 developed File Transfer Protocol front-end), but slightly modified.

The Ryte software does not use the similar_text() function for calculating text uniqueness and identifying duplicate content. It uses the Shingle algorithm which is also applied by Google.

The result of the comparison of two strings is always a percentage. A similar function is called Levenshtein distance, with which is calculated how a string has to be changed so that it is similar to another.

Syntax

The function syntax is as follows:

similar_text(string1,string2,percent)

Example

<?php
echo similar_text("Hallo Captain","Hello Serpino");
?>

Areas of application

The PHP function “similar_text” can handle different functions on websites:

  • Security feature: With the help of similar_text it can prevent a user selecting a password that is too similar to their real name or information which they have provided as part of registration.
  • Check feature: If you want to put a database on the web, for example, poems or algorithms, you can determine with this PHP function, if a similar text already exists. Furthermore, the same function can examine texts with regard to their similarity in a simple manner.

Disadvantages

If longer strings are checked, the PHP function similar_text () can be very slow, which may adversely affect the performance of a website. Therefore, this feature should be used only for short strings.