Giter Site home page Giter Site logo

php-finediff's People

Contributors

gorhill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-finediff's Issues

UTF-8 Help

I have 2 strings that contain HTML. I'm trying (unsuccessfully) to diff them, and then convert the result back to to HTML. I've tried the mb_convert_encoding() method, but can't seem to get things right.

Any help would be appreciated.

Excluding html tags while showing copied content

Hello, I am using php fine diff for showing duplicate content within websites but i am facing one problem which is that it includes html tag aatributes values also while comparing content. As i want character level granularity for this and when i am doing so the problem is that it will insert copy tag within html elements also.

I have attached the screenshot of problem ; its inserting copy tag in title attribute of anchor tag.
screenshot
Awaiting for your reply.

Opcode word

Hello !
I don't can't choose a diff per word.
My code :
$diff_opcodes = FineDiff::getDiffOpcodes($from_text, $to_text, 'word');
It's don't work.
Regards

Edit: It's OK, i have found

Identical strings

Hello,

When comparing two identical strings, FineDiff::getDiffOpcodes returns the index of the last char (ex.: c200). Is it the proper behaviour?

finediff destroys german Umlaute in html-result

I like your diff tool very much and most times it works fine for me.
If i try to diff a text with german Umlaute the result is not that nice.
Your tool recognize the changes but the result shows the Umlaute as html decoded.
Ü is shown as Ü and so on.

How to grab the deleted words (highlighted in red)?

Thanks for this great library. I am trying to create a module where two passages have to be compared and the wrongly typed words and not typed words have to be displayed separately. I found this library very useful. But, in this library, I couldn't find any method which can return wrongly typed words and not typed words separately, so that it can be stored in a variable.

Kindly reply if this can be achieved through this library.

Render cyrillic

Hi guys,
its a great library, but i have problem with Rendering on cyrillic symbols.

$from_text = "Някаква кирилица";
$to_text = "Някаква кирилица, тест";

$from_text = mb_convert_encoding($from_text, 'HTML-ENTITIES', 'UTF-8');
$to_text = mb_convert_encoding($to_text, 'HTML-ENTITIES', 'UTF-8');

$diff_opcodes = FineDiff::getDiffOpcodes($from_text, $to_text, 2);
$rendered_diff = FineDiff::renderDiffToHTMLFromOpcodes($from_text, $diff_opcodes);

echo $rendered_diff

When i try to print $rendered_diff it shows me:
������� ��������, ����

� => &.#.2.0.1.3.2.6.5.9.3.3; (without points)
Whats wrong with it?

I tested here http://www.raymondhill.net/finediff/viewdiff-ex.php and works great...

Mark stable release with v1.0

It would be good to mark some release with v1.0 tag to use it in composer. Since master can be unstable, it would be good to base our solutions off yours by tag, which will not be changed.

Doesn't properly handles TABS

When using your online demo, and pasting code with tabs, it doesn't preserve them after processing.

I haven't checked this behavior on my own installation, but I assume it will work the same.

The problem is I need the indentation with tabs to be preserved in the output.

Reverse diff opcode

Hello, a very good feature would be to get reverse diff opcodes.
I would like to log all changes in my forum (on subject or responses). But I don't keep the old version, only the newer. So I would like to compute old versions from the last version, not the opposite.

I try to switch arguments when calling FineDiff::getDiffOpcodes($from, $to) :

$firstVersion = "Test 123 - Heloa";
$newVersion = "Test 124 - Hello";
$opdiff = FineDiff::getDiffOpcodes($newVersion, $firstVersion)

But when I display, the difference (FineDiff::renderDiffToHTMLFromOpcodes), the modification are reversed (ins & del). So I tried something like :

$result = FineDiff::renderDiffToHTMLFromOpcodes($text, $opdiff);
// Replace ins by del & del by ins
$result = strtr($result, array('<del>' => '<ins>', '</del>' => '</ins>', '<ins>' => '<del>', '</ins>' => '</del>'));
// Swap ins & del
$result = preg_replace('#(<ins>.+?</ins>)(\s*)(<del>.+?</del>)#s', '$3$2$1', $result);

But, it's very ugly...
Could you do function FineDiff::getReverseDiffOpcodes for this case?

Thanks in advance,
Best Regards, Max

renderFromOpcodes should return Text

For whatever reason renderFromOpcodes takes in a callback which we're supposed to handle, however you don't process any return from the callback making it such that the function will always return NULL. As such one needs to create a global shared variable, set it to blank beforehand, call renderFromOpCodes with callback, modify global string in callback and then use global string afterwards. Wouldn't it be more in line with modern development practices and the rest of the library to have the renderFromOpcodes allow the callback to return a string which renderFromOpcodes concats and returns?

upload .diff

Currently one cannot upload an existing .diff file and let PHP-FineDiff properly parse the file and highlight the difference using some nice formatting. In my case I have two 3MB files to diff, so it is unfeasible to copy/paste all the info in a web browser. But I cannot generate a .diff off-line and upload it to a service that would take care of the appropriate formatting.

Words with a space added after...

I've noticed that in some situations using the 'word' granularity, something odd can happen. Take this work on it's own:

'Courier'

If I add the words ' Delivery Boy' after it (including the preceding white space), when it comes to viewing the difference it'll strike through the work 'Courier' and show 'Courier Delivery Boy' as being added instead.

Is there any way around this at all so it would show just ' Delivery Boy' as being added?

Breaks completely when dealing with html tags

I am comparing this string

<h3>Classsss Attendsance Guideliness for Extenuating Circusmstances</h3>

<p>In rare cases, students may have extenuating circumstances that make it impossible for them to attend all sessions of a class. These include military orders, court-imposed legal</p>

to this

<h3>Class Attendsance Guideliness for Extenuating Circusmstances</h3>

<p>In rare cases, students may have extenuating circumstances that make it impossible for them to attend all sessions of a class. These include military orders, court-imposed legal</p>

and get this

<div id="htmldiff" class="pane"><del><h3>Classss <ins><h3>Class Attendsance Guideliness for Extenuating Circusmstances</h3>

<p>In rare cases, students may have extenuating circumstances that make it impossible for them to attend all sessions of a class. These include military orders, court-imposed legal</p>

Incorrect double encoding of some special HTML characters

Hello Raymond,

Thank you writing and sharing FineDiff! I've been using it in several projects now. I would like to ask you something about how to resolve some situations I've run into.

The first one has to do when rendering to HTML. In some cases the result is double encoded. I've made a little test to explain how I use the library. (running on 5.3.3-7+squeeze19)

Test 1:

require_once __DIR__ . '/../classes/external/finediff/finediff.php';

$granularities = 1;
$from = "a b c";
$to = "a ’ a";

$diff_ops = \FineDiff::getDiffOpcodes($from, $to, $granularities);
$result = \FineDiff::renderDiffToHTMLFromOpcodes($from, $diff_ops);

header('HTTP/1.1 200 OK');
header('Content-type: text/html; charset=UTF-8');
echo $result;
die;

This results into:
a b&rsquo; ca
(a b’ ca)

After removing the second htmlentities call and adding the UTF-8 hint in finediff (line 684) the result is what I expected:
a b ca
(a b’ ca)

I think the problem is a combination of character encoding and some
HTML special characters like '’', '†', etc.

I'm not sure why the second htmlentities call is needed.
You must have done it for a reason so I hesitate to remove it from our codebase just yet.

The second test is with UTF-8. I've read your FAQ and did a few tests.
Test 2:

require_once __DIR__ . '/../classes/external/finediff/finediff.php';

$granularities = 1;
$from = "a b a";
$to = "a 中 a";

$from = mb_convert_encoding($from, 'HTML-ENTITIES', 'UTF-8');
$to = mb_convert_encoding($to, 'HTML-ENTITIES', 'UTF-8');

$diff_ops = \FineDiff::getDiffOpcodes($from, $to, $granularities);
$result = \FineDiff::renderDiffToHTMLFromOpcodes($from, $diff_ops);

header('HTTP/1.1 200 OK');
header('Content-type: text/html; charset=UTF-8');
echo $result;
die;

Result with calling: mb_conver_encoding:
a b&#20013; a

Result without calling: mb_conver_encoding:
a b中 a

Result calling with: mb_convert_encoding($from, "UTF-8");
a b中 a

When modifying the htmlentities call in finediff.php the codes works as expected without doing any conversion on the from and to strings.
a b&rsquo; ca
(a b中 a)

Thank you for reading my questions, I hope you have some time to point me in
a direction to work out these two use-cases.

Best regards,
Seb

PS.
Thought to let you know that on GitHub (https://github.com/gorhill/PHP-FineDiff) the link within your Copyright statement (http://raymondhill.net/blog/?p=441) doesn't seem to work any more.

Inline Diffs?

Is there any way to generate inline diffs ?

What i am talking about is how Github shows diffs -
3174017

Regards

finediff is eating my words when showing the comparisons.

After reading #18, I can now use finediff for Chinese successfully, but sometimes it will eat out my words!

Example:


(before)
1根據相對論,信息的傳播速度有限,因此在某些情况下,例如在發生宇宙膨胀時,距离我们非常遥远的區域中我們將只能收到一小部分区域的信息,其他部分的信息将永远无法传播到我们的區域。可以被我們觀測到的时空稱為“可觀測宇宙”、“可見宇宙”或“我們的宇宙”。應該強調,這是由於時空本身的结構造成的,與我們所用的觀測設備没有關係。 T'尸F.


(after)
根據相對論,信息的傳播速度有限,因此在某些情况下,例如在發生宇宙膨胀時,距离我们非常遥远的區中我們將只能收到一小部分区域的信息,其他部分的信息将永远无法传播到我们的區域。可以被我們觀測到的時

2空稱為“可觀測宇宙”、“可見宇宙”或“我們的宇宙”。應該強調,這是由於時空本身的结構造成的,與我們所用的觀測設備没有關係。


Using FineDiff::renderDiffToHTMLFromOpcodes($a, $opcodes), the result will just be:
根據相對論,信息的傳播速度有限,因此在某些情况下,例如在發生宇宙膨胀時,距离我们非常遥远的區域空稱為“可觀測宇宙”、“可見宇宙”或“我們的宇宙”。應該強調,這是由於時空本身的结構造成的,與我們所用的觀測設備没有關係。 T'尸F.


The whole "中我們將只能收到一小部分区域的信息,其他部分的信息将永远无法传播到我们的區域。可以被我們觀測到的時

2" is missing! I don;t know where to look at to solve the problem. Please give me some guidance. Thanks!

UTF-8 diff patch

Hello guys,

Thanks for this great library. As my dev computer is in PHP.5.4 and my other servers in PHP 5.3, there are many changes about UTF-8. I try to reduce the amount of modified code to handle this the simple way : replace htmlentities() call to a private static method with force the UTF-8 encoding.

private static function _htmlentities($input) {
return htmlentities($input, ENT_NOQUOTES | ENT_HTML5, 'UTF-8');
}

Download all the patch here:
http://dl.dropbox.com/u/62007491/diff-utf8-finediff.patch

Thanks for considering this patch. Hope this helps.

WISHLIST:Override <del> and <ins> html tags

It would be great if the <del> </del> and <ins> </ins> tags can be over ridden; it would also be nice then if the function name would change to something like renderDiffToMarkup.

This is very useful if one wants to create entries that include styling within the tag and not in css , or even use it for non html , such as generating svg or other XML or non XML markup documents.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.