Displays a human readable HTML table with the difference between two strings.
If the two strings are equivalent, wp_text_diff returns an empty string. Otherwise, returns an html table showing the changes. Deletions and insertions in text are marked up using the <del> and <ins> html tags, respectively.
Primary use is for for displaying changes between an older version and a new revision of the string.
@uses Text_Diff @uses WP_Text_Diff_Renderer_Table
<?php wp_text_diff( $left_string, $right_string, $args ); ?>
$left_string = 'This is the original string'; $right_string = 'This is the revised string'; $args = array( 'title' => 'Differences', 'title_left' => 'Old Version', 'title_right' => 'New Version' ); $diff_table = wp_text_diff($left_string,$right_string, $args); echo $diff_table;
This will output the following html:
<table class="diff"> <colgroup> <col class="ltype"> <col class="content"> <col class="ltype"> <col class="content"> </colgroup> <thead> <tr class="diff-title"> <th colspan="4">Differences</th> </tr> <tr class="diff-sub-title"> <td></td> <th>Old Version</th> <td></td> <th>New version</th> </tr> </thead> <tbody> <tr> <td>-</td> <td class="diff-deletedline"> This is the <del>original</del> string </td> <td>+</td> <td class="diff-addedline"> This is the <ins>revised</ins> string </td> </tr> </tbody> </table>
Sample output:
Differences | |||
---|---|---|---|
Old Version | New version | ||
- |
This is the |
+ |
This is the revised string |
Since: 2.6
wp_text_diff() is located in wp-includes/pluggable.php