Example of PHP Smart Differencer Output

This page contains an example of the output generated by SD's PHP Smart Differencer tool
when applied to an original file and an updated version of the same file.

Output from PHP Smart Differencer on original and updated file

This page contains an example of the output generated by SD's PHP Smart Differencer tool.
Observe that the Smart Differencer produces only 29 lines of output, compared to diff's 100 lines of output; the programmer simply has to look at less code. Note the added precision of Smart Differencer output: fine grain deltas with line and column number (l.c) ranges vs. full-line deltas, and the detection of renamed variables ('oldname' ->'newname') across a range of lines within an edit. Notice that source code formatting (different line breaks at line 58) don't fool the smart differencer, that changed comments don't confuse it, and that different way to express the same floating point value (line 225 in the diff output) and different escaping conventions that don't change its content in the string are ignored (line 351 in diff output).
For comparison, see deltas generated from a standard diff tool.


Delete 33.5-43.5 moving 33.5-43.5 to 102.5-113.5 with '$fctr'->'$factor'
<    function get_interest_factor($year_term, $monthly_interest_rate) {
<        global $base_rate;
<        
<        $fctr = 0; $base_rate   = 1 + $monthly_interest_rate;
<        $denominator = $base_rate;
<        for ($i=0; $i < ($year_term * 12); $i++) {
<            $fctr += (1 / $denominator);
<            $denominator *= $base_rate;
<        }
<        return $fctr;
<    }        
Insert 102.5-113.5 moving 33.5-43.5 to 102.5-113.5 with '$fctr'->'$factor'
>    function get_interest_factor($year_term, $monthly_interest_rate) {
>        global $base_rate;
>        
>        $factor      = 0;
>        $base_rate   = 1 + $monthly_interest_rate;
>        $denominator = $base_rate;
>        for ($i=0; $i < ($year_term * 12); $i++) {
>            $factor += (1 / $denominator);
>            $denominator *= $base_rate;
>        }
>        return $factor;
>    }        
Substitute 122.13-122.17 by 132.13-132.23
<            $temp                                
>            $month_term                                
Rename 289.27-375.9 to 299.27-385.9 with '$temp'->'$month_term'

Output from Cygwin diff tool

Note absence of column number data, absence of rename detection, failure to recognize reformatted code as unchanged (diff thinks the block of code at line 58 has changed), failure to notice same numeric values in the face of changed decimal point and radix (line 225), and failure to ignore the same comments of the moved function body.
See the actual deltas generated from PHP Smart Differencer.
See original file and updated version of the same file.


29,44d28
<     /* --------------------------------------------------- */
<     // This function does the actual mortgage calculations
<     // by plotting a PVIFA (Present Value Interest Factor of Annuity)
<     // table...
<     function get_interest_factor($year_term, $monthly_interest_rate) {
<         global $base_rate;
<         
<         $fctr = 0; $base_rate   = 1 + $monthly_interest_rate;
<         $denominator = $base_rate;
<         for ($i=0; $i < ($year_term * 12); $i++) {
<             $fctr += (1 / $denominator);
<             $denominator *= $base_rate;
<         }
<         return $fctr;
<     }        
< 
54a39,40
> 
> 
58,60c44,54
<     $sale_price = 0; $annual_interest_percent = 0; $year_term = 0; $down_percent = 0;
<     $this_year_interest_paid = 0; $this_year_principal_paid = 0;
<     $form_complete = false; $show_progress = false; $monthly_payment = false; $show_progress = false; $error = false;
---
>     $sale_price                      = 0;
>     $annual_interest_percent         = 0;
>     $year_term                       = 0;
>     $down_percent                    = 0;
>     $this_year_interest_paid         = 0;
>     $this_year_principal_paid        = 0;
>     $form_complete                   = false;
>     $show_progress                   = false;
>     $monthly_payment                 = false;
>     $show_progress                   = false;
>     $error                           = false;
104a99,114
>     // This function does the actual mortgage calculations
>     // by plotting a PVIFA (Present Value Interest Factor of Annuity)
>     // table...
>     function get_interest_factor($year_term, $monthly_interest_rate) {
>         global $base_rate;
>         
>         $factor      = 0;
>         $base_rate   = 1 + $monthly_interest_rate;
>         $denominator = $base_rate;
>         for ($i=0; $i < ($year_term * 12); $i++) {
>             $factor += (1 / $denominator);
>             $denominator *= $base_rate;
>         }
>         return $factor;
>     }        
>     /* --------------------------------------------------- */
122c132
<             $temp              = $year_term * 12;
---
>             $month_term              = $year_term * 12;
225c235
<                     $assessed_price          = ($sale_price * 85E-2);
---
>                     $assessed_price          = ($sale_price * .85);
289c299
<                     <?php echo $temp; ?> Months = <?php echo $year_term; ?> Years X 12
---
>                     <?php echo $month_term; ?> Months = <?php echo $year_term; ?> Years X 12
296c306
<                     Monthly Payment = <?php echo number_format($financing_price, "2", "", ""); ?> * (<?php echo number_format($monthly_interest_rate, "4", "", ""); ?> / (1 - ((1 + <?php echo number_format($monthly_interest_rate, "4", "", ""); ?>)<sup>-(<?php echo $temp; ?>)</sup>)))
---
>                     Monthly Payment = <?php echo number_format($financing_price, "2", "", ""); ?> * (<?php echo number_format($monthly_interest_rate, "4", "", ""); ?> / (1 - ((1 + <?php echo number_format($monthly_interest_rate, "4", "", ""); ?>)<sup>-(<?php echo $month_term; ?>)</sup>)))
309c319
<         $power = -($temp);
---
>         $power = -($month_term);
328c338
<         while ($current_month <= $temp) {        
---
>         while ($current_month <= $month_term) {        
351,358c361,368
<                 print("\011<tr valign=\"top\" bgcolor=\"#ffffcc\">\n");
<                 print("\011\011<td> </td>\n");
<                 print("\011\011<td colspan=\"3\">\n");
<                 print("\011\011\011You will spend \$" . number_format($total_spent_this_year, "2", ".", "thousands_sep") . " on your house in year " . $current_year . "<br>\n");
<                 print("\011\011\011\$" . number_format($this_year_interest_paid, "2", ".", "thousands_sep") . " will go towards INTEREST<br>\n");
<                 print("\011\011\011\$" . number_format($this_year_principal_paid, "2", ".", "thousands_sep") . " will go towards PRINCIPAL<br>\n");
<                 print("\011\011</td>\n");
<                 print("\011</tr>\n");
---
>                 print("\t<tr valign=\"top\" bgcolor=\"#ffffcc\">\n");
>                 print("\t\t<td> </td>\n");
>                 print("\t\t<td colspan=\"3\">\n");
>                 print("\t\t\tYou will spend \$" . number_format($total_spent_this_year, "2", ".", "thousands_sep") . " on your house in year " . $current_year . "<br>\n");
>                 print("\t\t\t\$" . number_format($this_year_interest_paid, "2", ".", "thousands_sep") . " will go towards INTEREST<br>\n");
>                 print("\t\t\t\$" . number_format($this_year_principal_paid, "2", ".", "thousands_sep") . " will go towards PRINCIPAL<br>\n");
>                 print("\t\t</td>\n");
>                 print("\t</tr>\n");
368c378
<                 if (($current_month + 6) < $temp) {
---
>                 if (($current_month + 6) < $month_term) {

Source Code before Change

This code is an open-source mortgate calculator. It has 428 lines, before an update was made.
See updated version of the same file.


<?php
    /*
        PHP Mortgage Calculator
        version: 1.1
        last update: Jan 1, 2003
        ----------------------------------------------------
        The PHP Mortgage Calculator tries to figure out a home 
        owners mortgage payments, and the breakdown of each monthly
        payment.
        
        The calculator accepts:
            Price (cost of home in US Dollars)
            Percentage of Down Payment
            Length of Mortgage
            Annual Interest Rate
        
        Based on the four items that the user enters, we can figure
        out the down payment (in US Dollars), the ammount that the 
        buyer needs to finance, and the monthly finance payment. 
        The calculator can also break down the monthly payments 
        so we know how much goes towards the mortgage's interest, 
        the mortgage's principal, the loan's Private Mortgage Insurance 
        (if less that 20% was used as a down payment), and an rough 
        estimate of the property's residential tax
        
        [ See below for LICENSE ]
    */
    
    /* --------------------------------------------------- */
    // This function does the actual mortgage calculations
    // by plotting a PVIFA (Present Value Interest Factor of Annuity)
    // table...
    function get_interest_factor($year_term, $monthly_interest_rate) {
        global $base_rate;
        
        $fctr = 0; $base_rate   = 1 + $monthly_interest_rate;
        $denominator = $base_rate;
        for ($i=0; $i < ($year_term * 12); $i++) {
            $fctr += (1 / $denominator);
            $denominator *= $base_rate;
        }
        return $fctr;
    }        

    /* --------------------------------------------------- *
     * Set Form DEFAULT values
     * --------------------------------------------------- */
    $default_sale_price              = "150000";
    $default_annual_interest_percent = 7.0;
    $default_year_term               = 30;
    $default_down_percent            = 10;
    $default_show_progress           = TRUE;
    /* --------------------------------------------------- */
    
    /* --------------------------------------------------- *
     * Initialize Variables
     * --------------------------------------------------- */
    $sale_price = 0; $annual_interest_percent = 0; $year_term = 0; $down_percent = 0;
    $this_year_interest_paid = 0; $this_year_principal_paid = 0;
    $form_complete = false; $show_progress = false; $monthly_payment = false; $show_progress = false; $error = false;
    /* --------------------------------------------------- */


    /* --------------------------------------------------- *
     * Set the USER INPUT values
     * --------------------------------------------------- */
    if (isset($_REQUEST['form_complete'])) {
        $sale_price                      = $_REQUEST['sale_price'];
        $annual_interest_percent         = $_REQUEST['annual_interest_percent'];
        $year_term                       = $_REQUEST['year_term'];
        $down_percent                    = $_REQUEST['down_percent'];
        $show_progress                   = (isset($_REQUEST['show_progress'])) ? $_REQUEST['show_progress'] : false;
        $form_complete                   = $_REQUEST['form_complete'];
    }
    /* --------------------------------------------------- */
    
    
    // If HTML headers have not already been sent, we'll print some here    
    if (!headers_sent()) {
        print("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'><HTML>");
        print("<head><title>Mortgage Calculator</title></HEAD><BODY>");
        print("<body bgcolor=\'#33ccff\'>");
        print("<H1 style=\'margin-bottom: 35px;\'>PHP Mortgage Calculator</h1>");
        print("<hr>\n\n");
        $print_footer = TRUE;
    } else {
       $print_footer = FALSE;
    }
    
    // Style Sheet
    ?>
    <style type="text/css">
        <!--
            td {
                font-size : 11px; 
                font-family : tahoma, helvetica, arial, lucidia, sans-serif; 
                color : #000000; 
            }
        -->
    </style> 


    <?php    
    /* --------------------------------------------------- */

    // If the form is complete, we'll start the math
    if ($form_complete) {
        // We'll set all the numeric values to JUST
        // numbers - this will delete any dollars signs,
        // commas, spaces, and letters, without invalidating
        // the value of the number
        $sale_price              = ereg_replace( "[^0-9.]", "", $sale_price);
        $annual_interest_percent = eregi_replace("[^0-9.]", "", $annual_interest_percent);
        $year_term               = eregi_replace("[^0-9.]", "", $year_term);
        $down_percent            = eregi_replace("[^0-9.]", "", $down_percent);
        
        if (((float) $year_term <= 0) || ((float) $sale_price <= 0) || ((float) $annual_interest_percent <= 0)) {
            $error = "You must enter a <b>Sale Price of Home</b>, <b>Length of Motgage</b> <i>and</i> <b>Annual Interest Rate</b>";
        }
        
        if (!$error) {
            $temp              = $year_term * 12;
            $down_payment            = $sale_price * ($down_percent / 100);
            $annual_interest_rate    = $annual_interest_percent / 100;
            $monthly_interest_rate   = $annual_interest_rate / 12;
            $financing_price         = $sale_price - $down_payment;
            $monthly_factor          = get_interest_factor($year_term, $monthly_interest_rate);
            $monthly_payment         = $financing_price / $monthly_factor;
        }
    } else {
        if (!$sale_price)              { $sale_price              = $default_sale_price;              }
        if (!$annual_interest_percent) { $annual_interest_percent = $default_annual_interest_percent; }
        if (!$year_term)               { $year_term               = $default_year_term;               }
        if (!$down_percent)            { $down_percent            = $default_down_percent;            }
        if (!$show_progress)           { $show_progress           = $default_show_progress;           }
    }
    
    if ($error) {
        print("<font color=\"red\">" . $error . "</font><br><br>\n");
        $form_complete   = false;
    }
?>
<font size="-1" color="#000000">This <b>mortgage calculator</b> can be used to figure out monthly payments of a home mortgage loan, based on the home's sale price, the term of the loan desired, buyer's down payment percentage, and the loan's interest rate. This calculator factors in PMI (Private Mortgage Insurance) for loans where less than 20% is put as a down payment. Also taken into consideration are the town property taxes, and their effect on the total monthly mortgage payment.<br></font>

<form method="GET" name="information" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="form_complete" value="1">
<table cellpadding="2" cellspacing="0" border="0" width="100%">
    <tr valign="top">
        <td align="right"><img src="/images/clear.gif" width="225" height="1" border="0" alt=""></td>
        <td align="smalltext" width="100%"><img src="/images/clear.gif" width="250" height="1" border="0" alt=""></td>
    </tr>
    <tr valign="top" bgcolor="#cccccc">
        <td align="center" colspan="2"><b>Purchase & Financing Information</b></td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td align="right">Sale Price of Home:</td>
        <td width="100%"><input type="text" size="10" name="sale_price" value="<?php echo $sale_price; ?>">(In Dollars)</td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td align="right">Percentage Down:</td>
        <td><input type="text" size="5" name="down_percent" value="<?php echo $down_percent; ?>">%</td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td align="right">Length of Mortgage:</td>
        <td><input type="text" size="3" name="year_term" value="<?php echo $year_term; ?>">years</td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td align="right">Annual Interest Rate:</td>
        <td><input type="text" size="5" name="annual_interest_percent" value="<?php echo $annual_interest_percent; ?>">%</td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td align="right">Explain Calculations:</td>
        <td><input type="checkbox" name="show_progress" value="1" <?php if ($show_progress) { print("checked"); } ?>> Show me the calculations and amortization</td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td> </td>
        <td><input type="submit" value="Calculate"><br><?php if ($form_complete) { print("<a href=\"" . $_SERVER['PHP_SELF'] . "\">Start Over</a><br>"); } ?><br></td>
    </tr>
<?php
    // If the form has already been calculated, the $down_payment
    // and $monthly_payment variables will be figured out, so we
    // can show them in this table
    if ($form_complete && $monthly_payment) {
?>
        <tr valign="top">
            <td align="center" colspan="2" bgcolor="#000000"><font color="#ffffff"><b>Mortgage Payment Information</b></font></td>
        </tr>
        <tr valign="top" bgcolor="#eeeeee">
            <td align="right">Down Payment:</td>
            <td><b><?php echo "\$" . number_format($down_payment, "2", ".", "thousands_sep"); ?></b></td>
        </tr>
        <tr valign="top" bgcolor="#eeeeee">
            <td align="right">Amount Financed:</td>
            <td><b><?php echo "\$" . number_format($financing_price, "2", ".", "thousands_sep"); ?></b></td>
        </tr>
        <tr valign="top" bgcolor="#cccccc">
            <td align="right">Monthly Payment:</td>
            <td><b><?php echo "\$" . number_format($monthly_payment, "2", ".", "thousands_sep"); ?></b><br><font>(Principal & Interest ONLY)</font></td>
        </tr>
        <?php
            if ($down_percent >= 20)
               $pmi_per_month=0; // no PMI
            else {
                $pmi_per_month = 55 * ($financing_price / 100000);
        ?>
                <tr valign="top" bgcolor="#FFFFCC">
                    <td align="right"> </td>
                    <td>
                        <br>
                        Since you are putting LESS than 20% down, you will need to pay PMI (<a href="http://www.google.com/search?hl=en&q=private+mortgage+insurance">Private Mortgage Insurance</a>), which tends to be about $55 per month for every $100,000 financed (until you have paid off 20% of your loan). This could add <?php echo "\$" . number_format($pmi_per_month, "2", ".", "thousands_sep"); ?> to your monthly payment.
                    </td>
                </tr>
                <tr valign="top" bgcolor="#FFFF99">
                    <td align="right">Monthly Payment:</td>
                    <td><b><?php echo "\$" . number_format(($monthly_payment + $pmi_per_month), "2", ".", "thousands_sep"); ?></b><br><font>(Principal & Interest, and PMI)</td>
                </tr>
        <?php
            }
        ?>
        <tr valign="top" bgcolor="#CCCCFF">
            <td align="right"> </td>
            <td>
                <br>
                <?php
                    $assessed_price          = ($sale_price * 85E-2);
                    $residential_yearly_tax  = ($assessed_price / 1000) * 14;
                    $residential_monthly_tax = $residential_yearly_tax / 12;
                    
                    if ($pmi_per_month == 0)
                        $pmi_text = "";
                    else {
                        $pmi_text = "PMI and ";
                    }
                ?>
                Residential (or Property) Taxes are a little harder to figure out... In Massachusetts, the average resedential tax rate seems to be around $14 per year for every $1,000 of your property's assessed value.
                <br><br>
                Let's say that your property's <i>assessed value</i> is 85% of what you actually paid for it - <?php echo "\$" . number_format($assessed_price, "2", ".", "thousands_sep"); ?>. This would mean that your yearly residential taxes will be around <?php echo "\$" . number_format($residential_yearly_tax, "2", ".", "thousands_sep"); ?>
                This could add <?php echo "\$" . number_format($residential_monthly_tax, "2", ".", "thousands_sep"); ?> to your monthly payment.
            </td>
        </tr>
        <tr valign="top" bgcolor="#9999FF">
            <td align="right">TOTAL Monthly Payment:</td>
            <td><b><?php echo "\$" . number_format(($monthly_payment + $pmi_per_month + $residential_monthly_tax), "2", ".", "thousands_sep"); ?></b><br><font>(including <?php echo $pmi_text; ?> residential tax)</font></td>
        </tr>
<?php    
    }
?>
</table>
</form>
<?php
    // This prints the calculation progress and 
    // the instructions of HOW everything is figured
    // out
    if ($form_complete && $show_progress) {
        $step = 1;
?>
        <br><br>
        <table cellpadding="5" cellspacing="0" border="1" width="100%">
            <tr valign="top">
                <td><b><?php echo $step++; ?></b></td>
                <td>
                    The <b>down payment</b> = The price of the home multiplied by the percentage down divided by 100 (for 5% down becomes 5/100 or 0.05)<br><br>
                    $<?php echo number_format($down_payment,"2",".","thousands_sep"); ?> = $<?php echo number_format($sale_price,"2",".","thousands_sep"); ?> X (<?php echo $down_percent; ?> / 100)
                </td>
            </tr>
            <tr valign="top">
                <td><b><?php echo $step++; ?></b></td>
                <td>
                    The <b>interest rate</b> = The annual interest percentage divided by 100<br><br>
                    <?php echo $annual_interest_rate; ?> = <?php echo $annual_interest_percent; ?>% / 100
                </td>
            </tr>
            <tr valign="top" bgcolor="#cccccc">
                <td colspan="2">
                    The <b>monthly factor</b> = The result of the following formula:
                </td>
            </tr>
            <tr valign="top">
                <td><b><?php echo $step++; ?></b></td>
                <td>
                    The <b>monthly interest rate</b> = The annual interest rate divided by 12 (for the 12 months in a year)<br><br>
                    <?php echo $monthly_interest_rate; ?> = <?php echo $annual_interest_rate; ?> / 12
                </td>
            </tr>
            <tr valign="top">
                <td><b><?php echo $step++; ?></b></td>
                <td>
                    The <b>month term</b> of the loan in months = The number of years you've taken the loan out for times 12<br><br>
                    <?php echo $temp; ?> Months = <?php echo $year_term; ?> Years X 12
                </td>
            </tr>
            <tr valign="top">
                <td><b><?php echo $step++; ?></b></td>
                <td>
                    The montly payment is figured out using the following formula:<br>
                    Monthly Payment = <?php echo number_format($financing_price, "2", "", ""); ?> * (<?php echo number_format($monthly_interest_rate, "4", "", ""); ?> / (1 - ((1 + <?php echo number_format($monthly_interest_rate, "4", "", ""); ?>)<sup>-(<?php echo $temp; ?>)</sup>)))
                    <br><br>
                    The <a href="#amortization">amortization</a> breaks down how much of your monthly payment goes towards the bank's interest, and how much goes into paying off the principal of your loan.
                </td>
            </tr>
        </table>
        <br>
<?php
        // Set some base variables
        $principal     = $financing_price;
        $current_month = 1;
        $current_year  = 1;
        // This basically, re-figures out the monthly payment, again.
        $power = -($temp);
        $denom = pow((1 + $monthly_interest_rate), $power);
        $monthly_payment = $principal * ($monthly_interest_rate / (1 - $denom));
        
        print("<br><br><a name=\"amortization\"></a>Amortization For Monthly Payment: <b>\$" . number_format($monthly_payment, "2", ".", "thousands_sep") . "</b> over " . $year_term . " years<br>\n");
        print("<table cellpadding=\"5\" cellspacing=\"0\" bgcolor=\"#eeeeee\" border=\"1\" width=\"100%\">\n");
        
        // This LEGEND will get reprinted every 12 months
        $legend  = "\t<tr valign=\"top\" bgcolor=\"#cccccc\">\n";
        $legend .= "\t\t<td align=\"right\"><b>Month</b></td>\n";
        $legend .= "\t\t<td align=\"right\"><b>Interest Paid</b></td>\n";
        $legend .= "\t\t<td align=\"right\"><b>Principal Paid</b></td>\n";
        $legend .= "\t\t<td align=\"right\"><b>Remaing Balance</b></td>\n";
        $legend .= "\t</tr>\n";
        
        echo $legend;
                
        // Loop through and get the current month's payments for 
        // the length of the loan 
        while ($current_month <= $temp) {        
            $interest_paid     = $principal * $monthly_interest_rate;
            $principal_paid    = $monthly_payment - $interest_paid;
            $remaining_balance = $principal - $principal_paid;
            
            $this_year_interest_paid  = $this_year_interest_paid + $interest_paid;
            $this_year_principal_paid = $this_year_principal_paid + $principal_paid;
            
            print("\t<tr valign=\"top\" bgcolor=\"#eeeeee\">\n");
            print("\t\t<td align=\"right\">" . $current_month . "</td>\n");
            print("\t\t<td align=\"right\">\$" . number_format($interest_paid, "2", ".", "thousands_sep") . "</td>\n");
            print("\t\t<td align=\"right\">\$" . number_format($principal_paid, "2", ".", "thousands_sep") . "</td>\n");
            print("\t\t<td align=\"right\">\$" . number_format($remaining_balance, "2", ".", "thousands_sep") . "</td>\n");
            print("\t</tr>\n");
    
            ($current_month % 12) ? $show_legend = FALSE : $show_legend = TRUE;
    
            if ($show_legend) {
                print("\t<tr valign=\"top\" bgcolor=\"#ffffcc\">\n");
                print("\t\t<td colspan=\"4\"><b>Totals for year " . $current_year . "</td>\n");
                print("\t</tr>\n");
                
                $total_spent_this_year = $this_year_interest_paid + $this_year_principal_paid;
                print("\011<tr valign=\"top\" bgcolor=\"#ffffcc\">\n");
                print("\011\011<td> </td>\n");
                print("\011\011<td colspan=\"3\">\n");
                print("\011\011\011You will spend \$" . number_format($total_spent_this_year, "2", ".", "thousands_sep") . " on your house in year " . $current_year . "<br>\n");
                print("\011\011\011\$" . number_format($this_year_interest_paid, "2", ".", "thousands_sep") . " will go towards INTEREST<br>\n");
                print("\011\011\011\$" . number_format($this_year_principal_paid, "2", ".", "thousands_sep") . " will go towards PRINCIPAL<br>\n");
                print("\011\011</td>\n");
                print("\011</tr>\n");
    
                print("\t<tr valign=\"top\" bgcolor=\"#ffffff\">\n");
                print("\t\t<td colspan=\"4\"> <br><br></td>\n");
                print("\t</tr>\n");
                
                $current_year++;
                $this_year_interest_paid  = 0;
                $this_year_principal_paid = 0;
                
                if (($current_month + 6) < $temp) {
                    echo $legend;
                }
            }
    
            $principal = $remaining_balance;
            $current_month++;
        }
        print("</table>\n");
    }
?>
<br>

<!-- END BODY -->


<?php
    if ($print_footer) {
        print("</body>\n");
        print("</BODY>
</HTML>\n");
    }

?>

<?php
/*
    ///// mortgage_calculator.php /////
    Copyright (c) 2002 David Tufts <http://dave.imarc.net> 
    All rights reserved.
    
    Redistribution and use in source and binary forms, with or without 
    modification, are permitted provided that the following conditions 
    are met:
    
    *    Redistributions of source code must retain the above copyright 
     notice, this list of conditions and the following disclaimer.
    *    Redistributions in binary form must reproduce the above 
     copyright notice, this list of conditions and the following 
     disclaimer in the documentation and/or other materials 
     provided with the distribution.
    *    Neither the name of David Tufts nor the names of its 
     contributors may be used to endorse or promote products 
     derived from this software without specific prior 
     written permission.
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
    BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
    TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
    POSSIBILITY OF SUCH DAMAGE.
*/
?>

Source Code after Change

This code is that same file at the next checkin with a number of changes (now 438 lines). It is hard to see the differences by simply looking at the text, partly just from the sheer size of it. This is why you want a diff tool of some kind.
See the actual deltas generated from PHP Smart Differencer.
For comparison, see deltas generated from a standard diff tool.


<?php
    /*
        PHP Mortgage Calculator
        version: 1.1
        last update: Jan 1, 2003
        ----------------------------------------------------
        The PHP Mortgage Calculator tries to figure out a home 
        owners mortgage payments, and the breakdown of each monthly
        payment.
        
        The calculator accepts:
            Price (cost of home in US Dollars)
            Percentage of Down Payment
            Length of Mortgage
            Annual Interest Rate
        
        Based on the four items that the user enters, we can figure
        out the down payment (in US Dollars), the ammount that the 
        buyer needs to finance, and the monthly finance payment. 
        The calculator can also break down the monthly payments 
        so we know how much goes towards the mortgage's interest, 
        the mortgage's principal, the loan's Private Mortgage Insurance 
        (if less that 20% was used as a down payment), and an rough 
        estimate of the property's residential tax
        
        [ See below for LICENSE ]
    */
    
    /* --------------------------------------------------- *
     * Set Form DEFAULT values
     * --------------------------------------------------- */
    $default_sale_price              = "150000";
    $default_annual_interest_percent = 7.0;
    $default_year_term               = 30;
    $default_down_percent            = 10;
    $default_show_progress           = TRUE;
    /* --------------------------------------------------- */
    


    /* --------------------------------------------------- *
     * Initialize Variables
     * --------------------------------------------------- */
    $sale_price                      = 0;
    $annual_interest_percent         = 0;
    $year_term                       = 0;
    $down_percent                    = 0;
    $this_year_interest_paid         = 0;
    $this_year_principal_paid        = 0;
    $form_complete                   = false;
    $show_progress                   = false;
    $monthly_payment                 = false;
    $show_progress                   = false;
    $error                           = false;
    /* --------------------------------------------------- */


    /* --------------------------------------------------- *
     * Set the USER INPUT values
     * --------------------------------------------------- */
    if (isset($_REQUEST['form_complete'])) {
        $sale_price                      = $_REQUEST['sale_price'];
        $annual_interest_percent         = $_REQUEST['annual_interest_percent'];
        $year_term                       = $_REQUEST['year_term'];
        $down_percent                    = $_REQUEST['down_percent'];
        $show_progress                   = (isset($_REQUEST['show_progress'])) ? $_REQUEST['show_progress'] : false;
        $form_complete                   = $_REQUEST['form_complete'];
    }
    /* --------------------------------------------------- */
    
    
    // If HTML headers have not already been sent, we'll print some here    
    if (!headers_sent()) {
        print("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'><HTML>");
        print("<head><title>Mortgage Calculator</title></HEAD><BODY>");
        print("<body bgcolor=\'#33ccff\'>");
        print("<H1 style=\'margin-bottom: 35px;\'>PHP Mortgage Calculator</h1>");
        print("<hr>\n\n");
        $print_footer = TRUE;
    } else {
       $print_footer = FALSE;
    }
    
    // Style Sheet
    ?>
    <style type="text/css">
        <!--
            td {
                font-size : 11px; 
                font-family : tahoma, helvetica, arial, lucidia, sans-serif; 
                color : #000000; 
            }
        -->
    </style> 


    <?php    
    /* --------------------------------------------------- */
    // This function does the actual mortgage calculations
    // by plotting a PVIFA (Present Value Interest Factor of Annuity)
    // table...
    function get_interest_factor($year_term, $monthly_interest_rate) {
        global $base_rate;
        
        $factor      = 0;
        $base_rate   = 1 + $monthly_interest_rate;
        $denominator = $base_rate;
        for ($i=0; $i < ($year_term * 12); $i++) {
            $factor += (1 / $denominator);
            $denominator *= $base_rate;
        }
        return $factor;
    }        
    /* --------------------------------------------------- */

    // If the form is complete, we'll start the math
    if ($form_complete) {
        // We'll set all the numeric values to JUST
        // numbers - this will delete any dollars signs,
        // commas, spaces, and letters, without invalidating
        // the value of the number
        $sale_price              = ereg_replace( "[^0-9.]", "", $sale_price);
        $annual_interest_percent = eregi_replace("[^0-9.]", "", $annual_interest_percent);
        $year_term               = eregi_replace("[^0-9.]", "", $year_term);
        $down_percent            = eregi_replace("[^0-9.]", "", $down_percent);
        
        if (((float) $year_term <= 0) || ((float) $sale_price <= 0) || ((float) $annual_interest_percent <= 0)) {
            $error = "You must enter a <b>Sale Price of Home</b>, <b>Length of Motgage</b> <i>and</i> <b>Annual Interest Rate</b>";
        }
        
        if (!$error) {
            $month_term              = $year_term * 12;
            $down_payment            = $sale_price * ($down_percent / 100);
            $annual_interest_rate    = $annual_interest_percent / 100;
            $monthly_interest_rate   = $annual_interest_rate / 12;
            $financing_price         = $sale_price - $down_payment;
            $monthly_factor          = get_interest_factor($year_term, $monthly_interest_rate);
            $monthly_payment         = $financing_price / $monthly_factor;
        }
    } else {
        if (!$sale_price)              { $sale_price              = $default_sale_price;              }
        if (!$annual_interest_percent) { $annual_interest_percent = $default_annual_interest_percent; }
        if (!$year_term)               { $year_term               = $default_year_term;               }
        if (!$down_percent)            { $down_percent            = $default_down_percent;            }
        if (!$show_progress)           { $show_progress           = $default_show_progress;           }
    }
    
    if ($error) {
        print("<font color=\"red\">" . $error . "</font><br><br>\n");
        $form_complete   = false;
    }
?>
<font size="-1" color="#000000">This <b>mortgage calculator</b> can be used to figure out monthly payments of a home mortgage loan, based on the home's sale price, the term of the loan desired, buyer's down payment percentage, and the loan's interest rate. This calculator factors in PMI (Private Mortgage Insurance) for loans where less than 20% is put as a down payment. Also taken into consideration are the town property taxes, and their effect on the total monthly mortgage payment.<br></font>

<form method="GET" name="information" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="form_complete" value="1">
<table cellpadding="2" cellspacing="0" border="0" width="100%">
    <tr valign="top">
        <td align="right"><img src="/images/clear.gif" width="225" height="1" border="0" alt=""></td>
        <td align="smalltext" width="100%"><img src="/images/clear.gif" width="250" height="1" border="0" alt=""></td>
    </tr>
    <tr valign="top" bgcolor="#cccccc">
        <td align="center" colspan="2"><b>Purchase & Financing Information</b></td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td align="right">Sale Price of Home:</td>
        <td width="100%"><input type="text" size="10" name="sale_price" value="<?php echo $sale_price; ?>">(In Dollars)</td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td align="right">Percentage Down:</td>
        <td><input type="text" size="5" name="down_percent" value="<?php echo $down_percent; ?>">%</td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td align="right">Length of Mortgage:</td>
        <td><input type="text" size="3" name="year_term" value="<?php echo $year_term; ?>">years</td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td align="right">Annual Interest Rate:</td>
        <td><input type="text" size="5" name="annual_interest_percent" value="<?php echo $annual_interest_percent; ?>">%</td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td align="right">Explain Calculations:</td>
        <td><input type="checkbox" name="show_progress" value="1" <?php if ($show_progress) { print("checked"); } ?>> Show me the calculations and amortization</td>
    </tr>
    <tr valign="top" bgcolor="#eeeeee">
        <td> </td>
        <td><input type="submit" value="Calculate"><br><?php if ($form_complete) { print("<a href=\"" . $_SERVER['PHP_SELF'] . "\">Start Over</a><br>"); } ?><br></td>
    </tr>
<?php
    // If the form has already been calculated, the $down_payment
    // and $monthly_payment variables will be figured out, so we
    // can show them in this table
    if ($form_complete && $monthly_payment) {
?>
        <tr valign="top">
            <td align="center" colspan="2" bgcolor="#000000"><font color="#ffffff"><b>Mortgage Payment Information</b></font></td>
        </tr>
        <tr valign="top" bgcolor="#eeeeee">
            <td align="right">Down Payment:</td>
            <td><b><?php echo "\$" . number_format($down_payment, "2", ".", "thousands_sep"); ?></b></td>
        </tr>
        <tr valign="top" bgcolor="#eeeeee">
            <td align="right">Amount Financed:</td>
            <td><b><?php echo "\$" . number_format($financing_price, "2", ".", "thousands_sep"); ?></b></td>
        </tr>
        <tr valign="top" bgcolor="#cccccc">
            <td align="right">Monthly Payment:</td>
            <td><b><?php echo "\$" . number_format($monthly_payment, "2", ".", "thousands_sep"); ?></b><br><font>(Principal & Interest ONLY)</font></td>
        </tr>
        <?php
            if ($down_percent >= 20)
               $pmi_per_month=0; // no PMI
            else {
                $pmi_per_month = 55 * ($financing_price / 100000);
        ?>
                <tr valign="top" bgcolor="#FFFFCC">
                    <td align="right"> </td>
                    <td>
                        <br>
                        Since you are putting LESS than 20% down, you will need to pay PMI (<a href="http://www.google.com/search?hl=en&q=private+mortgage+insurance">Private Mortgage Insurance</a>), which tends to be about $55 per month for every $100,000 financed (until you have paid off 20% of your loan). This could add <?php echo "\$" . number_format($pmi_per_month, "2", ".", "thousands_sep"); ?> to your monthly payment.
                    </td>
                </tr>
                <tr valign="top" bgcolor="#FFFF99">
                    <td align="right">Monthly Payment:</td>
                    <td><b><?php echo "\$" . number_format(($monthly_payment + $pmi_per_month), "2", ".", "thousands_sep"); ?></b><br><font>(Principal & Interest, and PMI)</td>
                </tr>
        <?php
            }
        ?>
        <tr valign="top" bgcolor="#CCCCFF">
            <td align="right"> </td>
            <td>
                <br>
                <?php
                    $assessed_price          = ($sale_price * .85);
                    $residential_yearly_tax  = ($assessed_price / 1000) * 14;
                    $residential_monthly_tax = $residential_yearly_tax / 12;
                    
                    if ($pmi_per_month == 0)
                        $pmi_text = "";
                    else {
                        $pmi_text = "PMI and ";
                    }
                ?>
                Residential (or Property) Taxes are a little harder to figure out... In Massachusetts, the average resedential tax rate seems to be around $14 per year for every $1,000 of your property's assessed value.
                <br><br>
                Let's say that your property's <i>assessed value</i> is 85% of what you actually paid for it - <?php echo "\$" . number_format($assessed_price, "2", ".", "thousands_sep"); ?>. This would mean that your yearly residential taxes will be around <?php echo "\$" . number_format($residential_yearly_tax, "2", ".", "thousands_sep"); ?>
                This could add <?php echo "\$" . number_format($residential_monthly_tax, "2", ".", "thousands_sep"); ?> to your monthly payment.
            </td>
        </tr>
        <tr valign="top" bgcolor="#9999FF">
            <td align="right">TOTAL Monthly Payment:</td>
            <td><b><?php echo "\$" . number_format(($monthly_payment + $pmi_per_month + $residential_monthly_tax), "2", ".", "thousands_sep"); ?></b><br><font>(including <?php echo $pmi_text; ?> residential tax)</font></td>
        </tr>
<?php    
    }
?>
</table>
</form>
<?php
    // This prints the calculation progress and 
    // the instructions of HOW everything is figured
    // out
    if ($form_complete && $show_progress) {
        $step = 1;
?>
        <br><br>
        <table cellpadding="5" cellspacing="0" border="1" width="100%">
            <tr valign="top">
                <td><b><?php echo $step++; ?></b></td>
                <td>
                    The <b>down payment</b> = The price of the home multiplied by the percentage down divided by 100 (for 5% down becomes 5/100 or 0.05)<br><br>
                    $<?php echo number_format($down_payment,"2",".","thousands_sep"); ?> = $<?php echo number_format($sale_price,"2",".","thousands_sep"); ?> X (<?php echo $down_percent; ?> / 100)
                </td>
            </tr>
            <tr valign="top">
                <td><b><?php echo $step++; ?></b></td>
                <td>
                    The <b>interest rate</b> = The annual interest percentage divided by 100<br><br>
                    <?php echo $annual_interest_rate; ?> = <?php echo $annual_interest_percent; ?>% / 100
                </td>
            </tr>
            <tr valign="top" bgcolor="#cccccc">
                <td colspan="2">
                    The <b>monthly factor</b> = The result of the following formula:
                </td>
            </tr>
            <tr valign="top">
                <td><b><?php echo $step++; ?></b></td>
                <td>
                    The <b>monthly interest rate</b> = The annual interest rate divided by 12 (for the 12 months in a year)<br><br>
                    <?php echo $monthly_interest_rate; ?> = <?php echo $annual_interest_rate; ?> / 12
                </td>
            </tr>
            <tr valign="top">
                <td><b><?php echo $step++; ?></b></td>
                <td>
                    The <b>month term</b> of the loan in months = The number of years you've taken the loan out for times 12<br><br>
                    <?php echo $month_term; ?> Months = <?php echo $year_term; ?> Years X 12
                </td>
            </tr>
            <tr valign="top">
                <td><b><?php echo $step++; ?></b></td>
                <td>
                    The montly payment is figured out using the following formula:<br>
                    Monthly Payment = <?php echo number_format($financing_price, "2", "", ""); ?> * (<?php echo number_format($monthly_interest_rate, "4", "", ""); ?> / (1 - ((1 + <?php echo number_format($monthly_interest_rate, "4", "", ""); ?>)<sup>-(<?php echo $month_term; ?>)</sup>)))
                    <br><br>
                    The <a href="#amortization">amortization</a> breaks down how much of your monthly payment goes towards the bank's interest, and how much goes into paying off the principal of your loan.
                </td>
            </tr>
        </table>
        <br>
<?php
        // Set some base variables
        $principal     = $financing_price;
        $current_month = 1;
        $current_year  = 1;
        // This basically, re-figures out the monthly payment, again.
        $power = -($month_term);
        $denom = pow((1 + $monthly_interest_rate), $power);
        $monthly_payment = $principal * ($monthly_interest_rate / (1 - $denom));
        
        print("<br><br><a name=\"amortization\"></a>Amortization For Monthly Payment: <b>\$" . number_format($monthly_payment, "2", ".", "thousands_sep") . "</b> over " . $year_term . " years<br>\n");
        print("<table cellpadding=\"5\" cellspacing=\"0\" bgcolor=\"#eeeeee\" border=\"1\" width=\"100%\">\n");
        
        // This LEGEND will get reprinted every 12 months
        $legend  = "\t<tr valign=\"top\" bgcolor=\"#cccccc\">\n";
        $legend .= "\t\t<td align=\"right\"><b>Month</b></td>\n";
        $legend .= "\t\t<td align=\"right\"><b>Interest Paid</b></td>\n";
        $legend .= "\t\t<td align=\"right\"><b>Principal Paid</b></td>\n";
        $legend .= "\t\t<td align=\"right\"><b>Remaing Balance</b></td>\n";
        $legend .= "\t</tr>\n";
        
        echo $legend;
                
        // Loop through and get the current month's payments for 
        // the length of the loan 
        while ($current_month <= $month_term) {        
            $interest_paid     = $principal * $monthly_interest_rate;
            $principal_paid    = $monthly_payment - $interest_paid;
            $remaining_balance = $principal - $principal_paid;
            
            $this_year_interest_paid  = $this_year_interest_paid + $interest_paid;
            $this_year_principal_paid = $this_year_principal_paid + $principal_paid;
            
            print("\t<tr valign=\"top\" bgcolor=\"#eeeeee\">\n");
            print("\t\t<td align=\"right\">" . $current_month . "</td>\n");
            print("\t\t<td align=\"right\">\$" . number_format($interest_paid, "2", ".", "thousands_sep") . "</td>\n");
            print("\t\t<td align=\"right\">\$" . number_format($principal_paid, "2", ".", "thousands_sep") . "</td>\n");
            print("\t\t<td align=\"right\">\$" . number_format($remaining_balance, "2", ".", "thousands_sep") . "</td>\n");
            print("\t</tr>\n");
    
            ($current_month % 12) ? $show_legend = FALSE : $show_legend = TRUE;
    
            if ($show_legend) {
                print("\t<tr valign=\"top\" bgcolor=\"#ffffcc\">\n");
                print("\t\t<td colspan=\"4\"><b>Totals for year " . $current_year . "</td>\n");
                print("\t</tr>\n");
                
                $total_spent_this_year = $this_year_interest_paid + $this_year_principal_paid;
                print("\t<tr valign=\"top\" bgcolor=\"#ffffcc\">\n");
                print("\t\t<td> </td>\n");
                print("\t\t<td colspan=\"3\">\n");
                print("\t\t\tYou will spend \$" . number_format($total_spent_this_year, "2", ".", "thousands_sep") . " on your house in year " . $current_year . "<br>\n");
                print("\t\t\t\$" . number_format($this_year_interest_paid, "2", ".", "thousands_sep") . " will go towards INTEREST<br>\n");
                print("\t\t\t\$" . number_format($this_year_principal_paid, "2", ".", "thousands_sep") . " will go towards PRINCIPAL<br>\n");
                print("\t\t</td>\n");
                print("\t</tr>\n");
    
                print("\t<tr valign=\"top\" bgcolor=\"#ffffff\">\n");
                print("\t\t<td colspan=\"4\"> <br><br></td>\n");
                print("\t</tr>\n");
                
                $current_year++;
                $this_year_interest_paid  = 0;
                $this_year_principal_paid = 0;
                
                if (($current_month + 6) < $month_term) {
                    echo $legend;
                }
            }
    
            $principal = $remaining_balance;
            $current_month++;
        }
        print("</table>\n");
    }
?>
<br>

<!-- END BODY -->


<?php
    if ($print_footer) {
        print("</body>\n");
        print("</BODY>
</HTML>\n");
    }

?>

<?php
/*
    ///// mortgage_calculator.php /////
    Copyright (c) 2002 David Tufts <http://dave.imarc.net> 
    All rights reserved.
    
    Redistribution and use in source and binary forms, with or without 
    modification, are permitted provided that the following conditions 
    are met:
    
    *    Redistributions of source code must retain the above copyright 
     notice, this list of conditions and the following disclaimer.
    *    Redistributions in binary form must reproduce the above 
     copyright notice, this list of conditions and the following 
     disclaimer in the documentation and/or other materials 
     provided with the distribution.
    *    Neither the name of David Tufts nor the names of its 
     contributors may be used to endorse or promote products 
     derived from this software without specific prior 
     written permission.
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
    BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
    TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
    POSSIBILITY OF SUCH DAMAGE.
*/
?>
For more information: Info@semanticdesigns.com    Follow us at Twitter: @SemanticDesigns

PHP Smart Differencer
Example