Last updated April 18, 2012. Created by Aren Cambre on May 18, 2009.
Edited by cluther. Log in to edit this page.
This compares the values of two text fields using PEAR.
<?php
$path = '/pathToPearsParentDirectory/pear/PEAR';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'PEAR.php';
include_once "Text/Diff.php";
include_once "Text/Diff/Renderer.php";
include_once "Text/Diff/Renderer/inline.php";
$diff = &new Text_Diff('auto', array(array($node->field_nameOfOneFieldToCompare[0]['value']), array($node->field_nameOfOtherFieldToCompare[0]['value'])));
$renderer = &new Text_Diff_Renderer_inline();
$node_field[0]['value'] = $renderer->render($diff);
?>Notes:
- Remove the
<?phpand?>from the code before pasting! - You must install PEAR's Text_Diff module. This isn't part of the standard install.
- The
$pathandset_include_pathlines are unnecessary if your PHP engine's include_path already includes the PEAR root directory. I had to override because I had to install my own copy of PEAR; my web host's version didn't include Text_Diff and was too out of date to allow the install. - Until #367281: Longtext field is broken is fixed, you should use varchar or text instead of longtext.
More details at http://arencambre.com/blog/2009/05/17/how-i-got-field-diffs-working-with...