Q:

Compare two text strings in PHP

I wonder how to compare two almost identical strings and output another string containing the new and the old value. It has to work wordwise. Actually its exactly what you can see on this page in the edit-history.
Example:
$string1 = 'A very, very nice day today.';
$string2 = 'An almost nice day today';

$output = compare_strings($string1, $string2);

Outputs: "A very, very An almost nice day today. today"
I know there is the text_diff package, but I want to know exactly how to do it manually.

I thought of creating an array with one entry per word and then compare them, but I don't know how to compare the best.

A:

Well, This is not a simple task, It requires more effort. I think you may know about sentiment analysis and Linguistics analysis,
Yes, It is a part of that and it is not easy.Although you can write the program for that but It can't have 100% accuracy. 
Go through this link: 
Linguistics analysis: http://en.wikipedia.org/wiki/Linguistics
And for sentiment analysis:
http://en.wikipedia.org/wiki/Sentiment_analysis
My suggestion: 
A. Go through linguistics analysis. 
B. Very simple way: Write a program, keep every word on array then compare two array and define some threshold(may be 70%) and find out
similar or not.
C. Make rule using positive and negative words, then map your sentence. 

