Diff::toString PHP Method

toString() public static method

$diff - the diff array $separator - the separator between lines; this optional parameter defaults to "\n"
public static toString ( $diff, $separator = " " )
    public static function toString($diff, $separator = "\n")
    {
        // initialise the string
        $string = '';
        // loop over the lines in the diff
        foreach ($diff as $line) {
            // extend the string with the line
            switch ($line[1]) {
                case self::UNMODIFIED:
                    $string .= '  ' . $line[0];
                    break;
                case self::DELETED:
                    $string .= '- ' . $line[0];
                    break;
                case self::INSERTED:
                    $string .= '+ ' . $line[0];
                    break;
            }
            // extend the string with the separator
            $string .= $separator;
        }
        // return the string
        return $string;
    }

Usage Example

Example #1
0
<?php

require_once "diff_class.php";
$microstart = explode(' ', microtime());
$start_time = $microstart[0] + $microstart[1];
echo Diff::toString(Diff::compareFiles('old_char_346.xml', 'char_346.xml', false));
$microstop = explode(' ', microtime());
$stop_time = $microstop[0] + $microstop[1];
echo "Expired time: " . ($stop_time - $start_time) . "<br>";
echo "Memory load: " . memory_get_usage() . " bytes";
All Usage Examples Of Diff::toString