Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    Guys, I've seen many examples of how we can compare two pieces of text with PHP and find out which areas have been added or removed. Can someone explain this to me? Or any code samples? I need this for a piece of web software I'm making.

    Many thanks!
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    Not really sure what your question means ...

    I usually look at this site:
    http://us.php.net/strings


  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    I know what you're talking about... this is something done in version control software to compare different versions of the same file.

    I've never seen code snippets for anything like this, but it would necessarily involve the use of arrays so you can move forward and backward line by line.

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Well, if you have the permissions to invoke an external program, GNU diff is the standard program used for this on UNIX systems. Diffs (as they are called) are, indeed, relatively commonplace in the open source world and in version control systems. In websites, they're particularly common in wiki systems. That said, I'd advise looking at some wiki systems to see how they implement it. MediaWiki seems to have a fairly good diff implementation.

    Google gives you some options. There's also a PEAR module called Text_Diff. A quick discussion of a couple of the diff options for PHP is on this blog post. That one's a request for a PHP unified diff implementation for use with the PHPUnit unit testing library.

    More information on diffs at the wikipedia article on diff.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:39 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com