略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: XMLDiff\DOM::diff

2024-11-23

XMLDiff\DOM::diff

(PECL xmldiff >= 0.8.0)

XMLDiff\DOM::diffDiff two DOMDocument objects

说明

public XMLDiff\DOM::diff(DOMDocument $from, DOMDocument $to): DOMDocument

Diff two DOMDocument instances and produce the new one containing the diff information.

参数

from

Source DOMDocument object.

to

Target DOMDocument object.

返回值

DOMDocument with the diff information or NULL.

add a noteadd a note

User Contributed Notes 1 note

up
0
jeewiya at gmail dot com
4 years ago
XMLDiff\DOM can be use like this, for compare xml files changes.

<?php
   

function getChangeElements($currentContent, $oldContent) {
        try {
           
$currentDoc = new DOMDocument();
           
$currentDoc->loadXML($currentContent);

           
$oldDoc = new DOMDocument();
           
$oldDoc->loadXML($oldContent);
           
$xmldiff = new XMLDiff\DOM();
            return
$xmldiff->diff($oldDoc, $currentDoc);
        } catch (
Exception $ex) {
            throw
$ex;
        }
    }

getChangeElements('updated.xml', 'old.xml');

?>

官方地址:https://www.php.net/manual/en/xmldiff-dom.diff.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3