Diff::toHTML PHP Method

toHTML() public static method

$diff - the diff array $separator - the separator between lines; this optional parameter defaults to '
'
public static toHTML ( $diff, $separator = '<br>' )
    public static function toHTML($diff, $separator = '<br>')
    {
        // initialise the HTML
        $html = '';
        // loop over the lines in the diff
        foreach ($diff as $line) {
            // extend the HTML with the line
            switch ($line[1]) {
                case self::UNMODIFIED:
                    $element = 'span';
                    break;
                case self::DELETED:
                    $element = 'del';
                    break;
                case self::INSERTED:
                    $element = 'ins';
                    break;
            }
            $html .= '<' . $element . '>' . htmlspecialchars($line[0]) . '</' . $element . '>';
            // extend the HTML with the separator
            $html .= $separator;
        }
        // return the HTML
        return $html;
    }

Usage Example

Example #1
0
    public function run3()
    {
        Qdmvc::loadHelper('class.Diff');
        $diff = Diff::compare('Ngay do', 'Ngay mua', true);
        echo Diff::toHTML($diff, '');
        return;
        foreach ($diff as $item) {
            if ($item[1] == Diff::DELETED) {
                echo $item[0];
            }
        }
        echo '<br>';
        foreach ($diff as $item) {
            if ($item[1] == Diff::INSERTED) {
                echo $item[0];
            }
        }
        ?>


        <?php 
    }
All Usage Examples Of Diff::toHTML