2014-09-05 07:44:07 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 09:19:14 +00:00
|
|
|
<!-- $Revision$ -->
|
2004-02-09 17:51:22 +00:00
|
|
|
<!-- Generated by xml_proto.php v2.0. Found in /scripts directory of phpdoc. -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xml:id="function.xdiff-string-diff" xmlns="http://docbook.org/ns/docbook">
|
2007-02-19 00:04:48 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>xdiff_string_diff</refname>
|
|
|
|
<refpurpose>Make unified diff of two strings</refpurpose>
|
|
|
|
</refnamediv>
|
2007-02-19 00:05:05 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2007-02-19 00:04:48 +00:00
|
|
|
<methodsynopsis>
|
2020-11-28 17:58:32 +00:00
|
|
|
<type>string</type><methodname>xdiff_string_diff</methodname>
|
2008-07-03 16:15:25 +00:00
|
|
|
<methodparam><type>string</type><parameter>old_data</parameter></methodparam>
|
|
|
|
<methodparam><type>string</type><parameter>new_data</parameter></methodparam>
|
2009-01-19 15:05:01 +00:00
|
|
|
<methodparam choice="opt"><type>int</type><parameter>context</parameter><initializer>3</initializer></methodparam>
|
2018-01-25 19:11:34 +00:00
|
|
|
<methodparam choice="opt"><type>bool</type><parameter>minimal</parameter><initializer>&false;</initializer></methodparam>
|
2007-02-19 00:04:48 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
2008-07-03 16:15:25 +00:00
|
|
|
Makes an unified diff containing differences between <parameter>old_data</parameter> string and
|
|
|
|
<parameter>new_data</parameter> string and returns it. The resulting diff is human-readable.
|
|
|
|
An optional <parameter>context</parameter> parameter specifies how many lines of context should be
|
2009-11-25 15:22:02 +00:00
|
|
|
added around each change. Setting <parameter>minimal</parameter> parameter
|
2008-07-03 16:15:25 +00:00
|
|
|
to true will result in outputting the shortest patch file possible (can take a long time).
|
2007-02-19 00:04:48 +00:00
|
|
|
</para>
|
2007-02-19 00:05:05 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2008-07-03 16:15:25 +00:00
|
|
|
<term><parameter>old_data</parameter></term>
|
2007-02-19 00:05:05 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2008-07-03 16:15:25 +00:00
|
|
|
First string with data. It acts as "old" data.
|
2007-02-19 00:05:05 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2008-07-03 16:15:25 +00:00
|
|
|
<term><parameter>new_data</parameter></term>
|
2007-02-19 00:05:05 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2008-07-03 16:15:25 +00:00
|
|
|
Second string with data. It acts as "new" data.
|
2007-02-19 00:05:05 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>context</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Indicates how many lines of context you want to include in the diff
|
2009-11-25 15:22:02 +00:00
|
|
|
result.
|
2007-02-19 00:05:05 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>minimal</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Set this parameter to &true; if you want to minimalize the size of the
|
2008-07-02 01:06:04 +00:00
|
|
|
result (can take a long time).
|
2007-02-19 00:05:05 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
2007-02-19 00:04:48 +00:00
|
|
|
<para>
|
2008-07-02 01:06:04 +00:00
|
|
|
Returns string with resulting diff or &false; if an internal error happened.
|
2007-02-19 00:04:48 +00:00
|
|
|
</para>
|
2007-02-19 00:05:05 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2007-02-19 00:04:48 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>xdiff_string_diff</function> example</title>
|
2004-02-09 17:51:22 +00:00
|
|
|
<para>
|
2007-02-19 00:04:48 +00:00
|
|
|
The following code makes unified diff of two articles.
|
2004-02-09 17:51:22 +00:00
|
|
|
</para>
|
2007-02-19 00:04:48 +00:00
|
|
|
<programlisting role="php">
|
2004-08-19 10:23:26 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$old_article = file_get_contents('./old_article.txt');
|
|
|
|
$new_article = $_REQUEST['article']; /* Let's say that someone pasted a new article to html form */
|
|
|
|
|
|
|
|
$diff = xdiff_string_diff($old_article, $new_article, 1);
|
|
|
|
if (is_string($diff)) {
|
|
|
|
echo "Differences between two articles:\n";
|
|
|
|
echo $diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
]]>
|
2007-02-19 00:04:48 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
2007-02-19 00:05:05 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
This function doesn't work well with binary strings. To make diff of binary
|
2008-07-03 16:15:25 +00:00
|
|
|
strings use <function>xdiff_string_bdiff</function>/<function>xdiff_string_rabdiff</function>.
|
2007-02-19 00:05:05 +00:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2007-02-19 00:04:48 +00:00
|
|
|
<para>
|
2007-02-19 00:05:05 +00:00
|
|
|
<simplelist>
|
2008-07-03 16:15:25 +00:00
|
|
|
<member><function>xdiff_string_patch</function></member>
|
2007-02-19 00:05:05 +00:00
|
|
|
</simplelist>
|
2007-02-19 00:04:48 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2004-02-09 17:51:22 +00:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2004-02-09 17:51:22 +00:00
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|