tags:

views:

76

answers:

1

I've these arrays:

<?php

// New
$array1 = array(
    array(
        'g_id' => '1',
        'g_title' => 'Root Admin',
        'g_perm_id' => '1',
        'g_bitoptions' => '0'
    ),
    array(
        'g_id' => '2',
        'g_title' => 'Member',
        'g_perm_id' => '2',
        'g_bitoptions' => '32'
    ),
    array(
        'g_id' => '3',
        'g_title' => 'Banned',
        'g_perm_id' => '3',
        'g_bitoptions' => '0'
    )
);

// Old
$array2 = array(
    array(
        'g_id' => '1',
        'g_title' => 'Admin',
        'g_perm_id' => '1',
        'g_bitoptions' => '0'
    ),
    array(
        'g_id' => '2',
        'g_title' => 'User',
        'g_perm_id' => '2',
        'g_bitoptions' => '0'
    ),
    array(
        'g_id' => '4',
        'g_title' => 'Validating',
        'g_perm_id' => '4',
        'g_bitoptions' => '0'
    )
);

What I'm want is an HTML visual difference between them, like this picture: http://img519.imageshack.us/i/diffe.png/

Anyone here knows any 3rd party class that do this? I've been looking at some but none of them had it. =/

Thank you in advance.

+1  A: 

Hi, this might not be directly related to your question. If you examine the sample image from the link, I am afraid the highlighted area is defined by javascript and/or rather than PHP - justification : because you cannot tell a simple diff() algorithm to get highlighting in that way.

So, try something like this:

When you "printing out" something in browser, assign attributes to color, say

<php code>
    <div class="red">blah blah blah</div>
    <div class="green">blah blah blah</div>
</php code>

The php code should do one thing only at the server side : to find the different parts, and so to generate corresponding class attributes.

Sorry I don't really have the time to write a solution to you at the moment.

In a word, the execution goes like this:

  1. You have php objects on server side
  2. Use php to find difference
  3. Use php to print pure html code
  4. Use css to highlight the coresponding area

I am sure this will do. And one advantage of doing it this way is that you have arbitrary control on how things gonna be look like on screen.

Use certainly can do everything on server side, that is, to hardcode all styles together with other html tags

Michael Mao