当前位置: 首页>>代码示例>>PHP>>正文


PHP xdiff_string_diff函数代码示例

本文整理汇总了PHP中xdiff_string_diff函数的典型用法代码示例。如果您正苦于以下问题:PHP xdiff_string_diff函数的具体用法?PHP xdiff_string_diff怎么用?PHP xdiff_string_diff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xdiff_string_diff函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: diff

 /**
  */
 function diff($from_lines, $to_lines)
 {
     array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
     array_walk($to_lines, array('Text_Diff', 'trimNewlines'));
     /* Convert the two input arrays into strings for xdiff processing. */
     $from_string = implode("\n", $from_lines);
     $to_string = implode("\n", $to_lines);
     /* Diff the two strings and convert the result to an array. */
     $diff = xdiff_string_diff($from_string, $to_string, count($to_lines));
     $diff = explode("\n", $diff);
     /* Walk through the diff one line at a time.  We build the $edits
      * array of diff operations by reading the first character of the
      * xdiff output (which is in the "unified diff" format).
      *
      * Note that we don't have enough information to detect "changed"
      * lines using this approach, so we can't add Text_Diff_Op_changed
      * instances to the $edits array.  The result is still perfectly
      * valid, albeit a little less descriptive and efficient. */
     $edits = array();
     foreach ($diff as $line) {
         switch ($line[0]) {
             case ' ':
                 $edits[] = new Text_Diff_Op_copy(array(substr($line, 1)));
                 break;
             case '+':
                 $edits[] = new Text_Diff_Op_add(array(substr($line, 1)));
                 break;
             case '-':
                 $edits[] = new Text_Diff_Op_delete(array(substr($line, 1)));
                 break;
         }
     }
     return $edits;
 }
开发者ID:ubertheme,项目名称:module-ubdatamigration,代码行数:36,代码来源:xdiff.php

示例2: merge

 /**
  * @inheritDoc
  */
 public function merge($base, $remote, $local)
 {
     // Skip merging if there is nothing to do.
     if ($merged = PhpMergeBase::simpleMerge($base, $remote, $local)) {
         return $merged;
     }
     // First try the built in xdiff_string_merge3.
     $merged = xdiff_string_merge3($base, $remote, $local, $error);
     //        if ($error) {
     //            // Try it the other way around.
     //            $error = null;
     //            $merged = xdiff_string_merge3($base, $local, $remote, $error);
     //        }
     if ($error) {
         // So there might be a merge conflict.
         $baseLines = $this->base = Line::createArray(array_map(function ($l) {
             return [$l, 0];
         }, explode("\n", $base)));
         // Get patch strings and transform them to Hunks.
         $remotePatch = xdiff_string_diff($base, $remote, 0);
         $localPatch = xdiff_string_diff($base, $local, 0);
         // Note that patching $remote with $localPatch will work only in
         // some cases because xdiff patches differently than git and will
         // apply the same change twice.
         $remote_hunks = self::interpretDiff($remotePatch);
         $local_hunks = self::interpretDiff($localPatch);
         // Merge Hunks and detect conflicts the same way PhpMerge does.
         $conflicts = [];
         $merged = PhpMerge::mergeHunks($baseLines, $remote_hunks, $local_hunks, $conflicts);
         if ($conflicts) {
             throw new MergeException('A merge conflict has occured.', $conflicts, $merged);
         }
     }
     return $merged;
 }
开发者ID:bircher,项目名称:php-merge,代码行数:38,代码来源:XdiffMerge.php

示例3: compareStringToString

 public static function compareStringToString($str1, $str2)
 {
     $compare_result = NULL;
     // wrapping the words
     $str1 = wordwrap($str1, 1);
     $str2 = wordwrap($str2, 1);
     // Diff
     $compare_result = xdiff_string_diff($str1, $str2);
     return $compare_result;
 }
开发者ID:TBoonX,项目名称:SlideWiki,代码行数:10,代码来源:SlideCompare.php

示例4: diffString

 public function diffString($stringFrom, $stringTo)
 {
     // fix "no new lineat the end" problem.
     if (!ereg("\n\$", $stringFrom)) {
         $stringFrom .= "\n";
     }
     if (!ereg("\n\$", $stringTo)) {
         $stringTo .= "\n";
     }
     return xdiff_string_diff($stringFrom, $stringTo);
 }
开发者ID:jbzdak,项目名称:wikidot,代码行数:11,代码来源:ODiff.php

示例5: createDiff

function createDiff($source, $newfile, $id, $oldsource, $oldfile, $oldid)
{
    // Try different ways of diffing, in order of preference.
    if (function_exists('xdiff_string_diff')) {
        // The PECL xdiff PHP-extension.
        $difftext = xdiff_string_diff($oldsource['sourcecode'], $source['sourcecode'], 2, TRUE);
    } elseif (!(bool) ini_get('safe_mode') || strtolower(ini_get('safe_mode')) == 'off') {
        // Only try executing diff when safe_mode is off, otherwise
        // the shell exec will fail.
        if (is_readable($oldfile) && is_readable($newfile)) {
            // A direct diff on the sources in the SUBMITDIR.
            $difftext = systemDiff($oldfile, $newfile);
        } else {
            // Try generating temporary files for executing diff.
            $oldfile = tempnam(TMPDIR, "source-old-s{$oldid}-");
            $newfile = tempnam(TMPDIR, "source-new-s{$id}-");
            if (!$oldfile || !$newfile) {
                $difftext = "DOMjudge: error generating temporary files for diff.";
            } else {
                $oldhandle = fopen($oldfile, 'w');
                $newhandle = fopen($newfile, 'w');
                if (!$oldhandle || !$newhandle) {
                    $difftext = "DOMjudge: error opening temporary files for diff.";
                } else {
                    if (fwrite($oldhandle, $oldsource['sourcecode']) === FALSE || fwrite($newhandle, $source['sourcecode']) === FALSE) {
                        $difftext = "DOMjudge: error writing temporary files for diff.";
                    } else {
                        $difftext = systemDiff($oldfile, $newfile);
                    }
                }
                if ($oldhandle) {
                    fclose($oldhandle);
                }
                if ($newhandle) {
                    fclose($newhandle);
                }
            }
            if ($oldfile) {
                unlink($oldfile);
            }
            if ($newfile) {
                unlink($newfile);
            }
        }
    } else {
        $difftext = "DOMjudge: diff functionality not available in PHP or via shell exec.";
    }
    return $difftext;
}
开发者ID:rohit-takhar,项目名称:domjudge,代码行数:49,代码来源:show_source.php

示例6: diff

 /**
  */
 public function diff($from_lines, $to_lines)
 {
     if (!extension_loaded('xdiff')) {
         throw new Horde_Text_Diff_Exception('The xdiff extension is required for this diff engine');
     }
     array_walk($from_lines, ['Horde_Text_Diff', 'trimNewlines']);
     array_walk($to_lines, ['Horde_Text_Diff', 'trimNewlines']);
     /* Convert the two input arrays into strings for xdiff processing. */
     $from_string = implode("\n", $from_lines);
     $to_string = implode("\n", $to_lines);
     /* Diff the two strings and convert the result to an array. */
     $diff = xdiff_string_diff($from_string, $to_string, count($to_lines));
     $diff = explode("\n", $diff);
     /* Walk through the diff one line at a time.  We build the $edits
      * array of diff operations by reading the first character of the
      * xdiff output (which is in the "unified diff" format).
      *
      * Note that we don't have enough information to detect "changed"
      * lines using this approach, so we can't add Horde_Text_Diff_Op_Changed
      * instances to the $edits array.  The result is still perfectly
      * valid, albeit a little less descriptive and efficient. */
     $edits = [];
     foreach ($diff as $line) {
         if (!strlen($line)) {
             continue;
         }
         switch ($line[0]) {
             case ' ':
                 $edits[] = new Horde_Text_Diff_Op_Copy([substr($line, 1)]);
                 break;
             case '+':
                 $edits[] = new Horde_Text_Diff_Op_Add([substr($line, 1)]);
                 break;
             case '-':
                 $edits[] = new Horde_Text_Diff_Op_Delete([substr($line, 1)]);
                 break;
         }
     }
     return $edits;
 }
开发者ID:ByMyHandsOnly,项目名称:BMHO_Web,代码行数:42,代码来源:Xdiff.php

示例7: foreach

     I2CE::raiseError("WARNING: Cannot write to directory {$target_dir}", E_USER_ERROR);
 }
 foreach ($translated_files as $file => $contents) {
     $target_file = $target_dir . $file;
     if (is_file($target_file) && is_readable($target_file)) {
         $existing = file_get_contents($target_file);
         if (false === $existing) {
             I2CE::raiseError("WARNING: Translation to {$locale} for {$file} in {$module} exists but is not readable. -- Skipping");
             continue;
         }
         if ($contents == $existing) {
             continue;
         } else {
             $msg = "There is an existing translation to {$locale} for {$file} in the module {$module}.  Overwrite? ";
             if (function_exists('xdiff_string_diff')) {
                 $diff = xdiff_string_diff($existing, $contents, 1);
             } else {
                 if ($first_time) {
                     $msg .= "\nFor more information, run (on ubunutu):\n\tsudo apt-get install re2c  php5-dev build-essential wget\n\tmkdir -p /tmp/src\n\tcd /tmp/src\n\twget http://www.xmailserver.org/libxdiff-0.22.tar.gz\n\ttar -xzf libxdiff-0.22.tar.gz \n\tcd libxdiff-0.22\n\t./configure\n\tmake\n\tsudo make install\n\tsudo pecl install xdiff\n\techo \"extension=xdiff.so\" | sudo tee /etc/php5/conf.d/xdiff.ini \n";
                 }
                 $first_time = false;
                 $diff = false;
             }
             if (prompt($msg, $booleans['overwrite-all'], $diff)) {
                 unlink($target_file);
             } else {
                 continue;
             }
         }
     }
     if (false === file_put_contents($target_file, $contents)) {
开发者ID:apelon-ohie,项目名称:ihris-site,代码行数:31,代码来源:translate_templates.php

示例8: diff

function diff($string1, $string2)
{
    if (!extension_loaded("xdiff")) {
        $result = @dl("xdiff.so");
        // avoid the E_WARNING
        if (!$result) {
            return "Note: xdiff not available for diffing. Outputting both strings:\nString1:\n{$string1}\nString2:\n{$string2}";
        }
    }
    if (strlen($string1) > 5000000 || strlen($string2) > 5000000) {
        return "Too big to xdiff. Outputting both strings:\nString1:\n{$string1}\nString2:\n{$string2}";
    }
    return xdiff_string_diff("{$string1}\n", "{$string2}\n");
}
开发者ID:michaelprem,项目名称:phc,代码行数:14,代码来源:header.php

示例9: tftpd_db_write_config

function tftpd_db_write_config(&$db, &$data)
{
    /* Our $db object still contains the query results from the authentication
     * query earlier. Lets retrieve the device id so we update the proper
     * configuration file
     */
    $r = $db->get_row();
    $device = $r['id'];
    $filename = $r['filename'];
    /* Retrieve old configuration data
     * Only create patch if we have a previous config
     */
    $sql = "SELECT content FROM configurations WHERE device='" . $device . "'";
    tftpd_log('25', 'sql query string: "' . $sql . '"');
    if ($db->query($sql) > 0) {
        /* Create patch */
        $r = $db->get_row($sql);
        $old_data = $r['content'];
        $patch = xdiff_string_diff($data, $old_data);
        /* Don't save an empty patch */
        if ($patch != '') {
            /* Escape the data before accessing db */
            $patch = mysql_real_escape_string($patch);
            /* Insert the patch into the database */
            $sql = "INSERT INTO patches (id, device, ts, content) VALUES ('0','{$device}',NOW(),'{$patch}')";
            tftpd_log('25', 'sql query string: "' . $sql . '"');
            if ($db->query($sql) > 0) {
                tftpd_log('1', 'db: patch table updated');
            } else {
                tftpd_log('0', 'db: patch table update failed');
            }
        }
        /* Prepare query to update the configuration */
        $data = mysql_real_escape_string($data);
        $sql = "UPDATE configurations SET content='{$data}' WHERE device='{$device}'";
    } else {
        /* Prepare query to insert the configuration */
        $data = mysql_real_escape_string($data);
        $sql = "INSERT INTO configurations (device, content) VALUES ('{$device}', '{$data}')";
    }
    tftpd_log('25', 'sql query string: "' . $sql . '"');
    $db->query($sql);
    tftpd_log('1', 'db: configurations table updated');
    /* REPLACE the timestamp */
    $sql = "REPLACE INTO updated (device, ts) " . "VALUES ('{$device}',NOW())";
    tftpd_log('25', 'sql query string: "' . $sql . '"');
    $db->query($sql);
}
开发者ID:americandigitalservices,项目名称:cisco-config-manager,代码行数:48,代码来源:tftpd-config.php

示例10: dBug

// $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;
// }
$version_a = 1;
$version_b = 2;
$tcase_id = 88;
$va = $tcase_mgr->get_by_id($tcase_id, null, 'ALL', 'ALL', $version_a);
$vb = $tcase_mgr->get_by_id($tcase_id, null, 'ALL', 'ALL', $version_b);
new dBug($va);
new dBug($vb);
$diff = xdiff_string_diff($va[0]['summary'], $vb[0]['summary'], 1);
echo "Differences between two articles:\n";
echo $diff;
die;
// getByPathName
// function getByPathName($pathName,$pathSeparator='::')
$pathName = 'ZATHURA::Holodeck::Apollo 10 Simulation::Unload::Full speed unload';
$fname = 'getByPathName';
echo "<pre> testcase - {$fname}(\$pathName,\$pathSeparator='::')";
echo "</pre>";
echo "<pre>            {$fname}({$pathName})";
echo "</pre>";
$result = $tcase_mgr->{$fname}($pathName);
new dBug($result);
die;
$tcase_id = 318;
开发者ID:CristianOspinaOspina,项目名称:testlinkpruebas,代码行数:31,代码来源:testcase.class.test.php

示例11: GetXDiff

 /**
  * Get diff using xdiff
  *
  * @param string $fromData from file data
  * @param string $toData to file data
  * @param integer $context context lines
  * @return string diff content
  */
 private function GetXDiff($fromData, $toData, $context = 3)
 {
     return xdiff_string_diff($fromData, $toData, $context);
 }
开发者ID:fboender,项目名称:gitphp,代码行数:12,代码来源:FileDiff.class.php

示例12: GetXDiff

 /**
  * GetXDiff
  *
  * Get diff using xdiff
  *
  * @access private
  * @param int $context number of context lines
  * @param boolean $header true to include standard diff header
  * @param string $file override the file name
  * @return string diff content
  */
 private function GetXDiff($context = 3, $header = true, $file = null)
 {
     if (!function_exists('xdiff_string_diff')) {
         return '';
     }
     $fromData = '';
     $toData = '';
     $isBinary = false;
     $fromName = '/dev/null';
     $toName = '/dev/null';
     if (empty($this->status) || $this->status == 'M' || $this->status == 'D') {
         $fromBlob = $this->GetFromBlob();
         $isBinary = $isBinary || $fromBlob->IsBinary();
         $fromData = $fromBlob->GetData(false);
         $fromName = 'a/';
         if (!empty($file)) {
             $fromName .= $file;
         } else {
             if (!empty($this->fromFile)) {
                 $fromName .= $this->fromFile;
             } else {
                 $fromName .= $this->fromHash;
             }
         }
     }
     if (empty($this->status) || $this->status == 'M' || $this->status == 'A') {
         $toBlob = $this->GetToBlob();
         $isBinary = $isBinary || $toBlob->IsBinary();
         $toData = $toBlob->GetData(false);
         $toName = 'b/';
         if (!empty($file)) {
             $toName .= $file;
         } else {
             if (!empty($this->toFile)) {
                 $toName .= $this->toFile;
             } else {
                 $toName .= $this->toHash;
             }
         }
     }
     $output = '';
     if ($isBinary) {
         $output = sprintf(__('Binary files %1$s and %2$s differ'), $fromName, $toName) . "\n";
     } else {
         if ($header) {
             $output = '--- ' . $fromName . "\n" . '+++ ' . $toName . "\n";
         }
         $output .= xdiff_string_diff($fromData, $toData, $context);
     }
     return $output;
 }
开发者ID:sandassha,项目名称:gitstack,代码行数:62,代码来源:FileDiff.class.php


注:本文中的xdiff_string_diff函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。