Web Analytics Made Easy -
StatCounter Comparing text changes - CodingForum

Announcement

Collapse
No announcement yet.

Comparing text changes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Comparing text changes

    So let's just say I have this text stored in my database:

    "I just posted a topic."

    I also have this stored:

    "I just posted a thread."

    How can I output a list of the differences or like - output the second one with the difference highlighted?

    Thanks!

  • #2
    Something like this?
    PHP Code:
    <?php
    $str1 
    'I just posted a topic.';
    $str2 'I just posted a thread.';
    if(
    strcmp($str1$str2) >= 0)
    {
        
    $n strlen($str2);
    }
    else
    {
        
    $n strlen($str1);
    }
    $result = array();
    for(
    $i 0$i $n$i++)
    {
        if(
    $str1{$i} != $str2{$i})
        {
            
    $result[0][] .= '<font color="#FF0000">' $str1{$i} . '</font>';
            
    $result[1][] .= '<font color="#FF0000">' $str2{$i} . '</font>';        
        }
        else
        {
            
    $result[0][] .= $str1{$i};
            
    $result[1][] .= $str2{$i};        
        }
    }
    $result = array(implode(''$result[0]), implode(''$result[1]));
    print 
    $result[0] . "<br />\n" $result[1]; 
    ?>
    I'm not sure what you want.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

    Comment

    Working...
    X