mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 13:57:03 +08:00
144 lines
6.4 KiB
HTML
144 lines
6.4 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>Make unified diff of two strings</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.xdiff-string-diff" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">xdiff_string_diff</h1>
|
|
<p class="verinfo">(PECL xdiff >= 0.2.0)</p><p class="refpurpose"><span class="refname">xdiff_string_diff</span> — <span class="dc-title">Make unified diff of two strings</span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.xdiff-string-diff-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>xdiff_string_diff</strong></span>
|
|
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$old_data</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$new_data</code></span>
|
|
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$context</code><span class="initializer"> = 3</span></span>
|
|
[, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$minimal</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
|
|
]] ) : <span class="type">string</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
Makes an unified diff containing differences between <code class="parameter">old_data</code> string and
|
|
<code class="parameter">new_data</code> string and returns it. The resulting diff is human-readable.
|
|
An optional <code class="parameter">context</code> parameter specifies how many lines of context should be
|
|
added around each change. Setting <code class="parameter">minimal</code> parameter
|
|
to true will result in outputting the shortest patch file possible (can take a long time).
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.xdiff-string-diff-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">old_data</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
First string with data. It acts as "old" data.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">new_data</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Second string with data. It acts as "new" data.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">context</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Indicates how many lines of context you want to include in the diff
|
|
result.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">minimal</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
Set this parameter to <strong><code>TRUE</code></strong> if you want to minimalize the size of the
|
|
result (can take a long time).
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.xdiff-string-diff-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
Returns string with resulting diff or <strong><code>FALSE</code></strong> if an internal error happened.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.xdiff-string-diff-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-2873">
|
|
<p><strong>Example #1 <span class="function"><strong>xdiff_string_diff()</strong></span> example</strong></p>
|
|
<div class="example-contents"><p>
|
|
The following code makes unified diff of two articles.
|
|
</p></div>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$old_article </span><span style="color: #007700">= </span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'./old_article.txt'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$new_article </span><span style="color: #007700">= </span><span style="color: #0000BB">$_REQUEST</span><span style="color: #007700">[</span><span style="color: #DD0000">'article'</span><span style="color: #007700">]; </span><span style="color: #FF8000">/* Let's say that someone pasted a new article to html form */<br /><br /></span><span style="color: #0000BB">$diff </span><span style="color: #007700">= </span><span style="color: #0000BB">xdiff_string_diff</span><span style="color: #007700">(</span><span style="color: #0000BB">$old_article</span><span style="color: #007700">, </span><span style="color: #0000BB">$new_article</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">is_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$diff</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #DD0000">"Differences between two articles:\n"</span><span style="color: #007700">;<br /> echo </span><span style="color: #0000BB">$diff</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 notes" id="refsect1-function.xdiff-string-diff-notes">
|
|
<h3 class="title">注释</h3>
|
|
<blockquote class="note"><p><strong class="note">Note</strong>:
|
|
<p class="para">
|
|
This function doesn't work well with binary strings. To make diff of binary
|
|
strings use <span class="function"><a href="xdiff_string_bdiff.html" class="function">xdiff_string_bdiff()</a></span>/<span class="function"><a href="xdiff_string_rabdiff.html" class="function">xdiff_string_rabdiff()</a></span>.
|
|
</p>
|
|
</p></blockquote>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.xdiff-string-diff-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="xdiff_string_patch.html" class="function" rel="rdfs-seeAlso">xdiff_string_patch()</a> - Patch a string with an unified diff</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |