String difference php

Viewed 6613

I want to create a method which compares two sentence and returns the words that makes them different.

e.g

grey tiles 100 X 200 kitchen flooring

grey tiles 300 X 600 kitchen flooring

difference are 100 x 200 300 x 600

it will allow one single word (not necesary one character to sit between two unique words) though if the distance exceeds by one it will throw an error saying the phrases are not similar enough the difference can be found at the start/ end / middle of the text

after passing to different blogs, i found similar approach to my concern using the native php function xdiff_string_diff but the problem is, I cant make the code works. I got error saying xdiff_string_diff is undefined function. Anyone of you knows what extensions should be loaded to make this function available? Or if you can suggest another approach it will be great and much appreciated. :)

<?php
$old_article = "grey tiles 100 X 200 kitchen flooring";
$new_article = "grey tiles 300 X 600 kitchen flooring"

$diff = xdiff_string_diff($old_article, $new_article, 1);
if (is_string($diff)) {
    echo "Differences between two articles:\n";
    echo $diff;
}

?>
3 Answers
Related