How to calculate percent difference (or similarity) between two strings?

4

I'm using PHP in an application I'm developing, where I have a text editor.

In this text editor, with each change made, before saving, I create a record with the original data (that is, how they are before the change is complete).

In addition, I have now come up with a demand where I need to calculate the percentage change of texts as well as figure out which excerpt each user has edited.

I think I'm halfway to knowing every bit edited through this question: Compare php texts

a>

But I need to know: Is there any way to calculate the percentage of difference (or similarity) between two texts in PHP?

How can I do this?

    
asked by anonymous 29.06.2018 / 16:48

1 answer

1

Percentage similarity

In PHP there is a function called similar_text , it serves to find the similarity between two strings . Here is the description of the language documentation about this function:

  

similar_text - Calculate the similarity between two strings

Knowing the purpose of the function, just add a third parameter that gives the percentage of similarity.

similar_text('Hello World!', 'Hello World!', $percentage);
echo $percentage; // Resulta 100, que é a porcentagem.
    
01.07.2018 / 16:18