Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

UTF-8 diff patch #11

Open
fr-freelance opened this issue Sep 12, 2012 · 8 comments
Open

UTF-8 diff patch #11

fr-freelance opened this issue Sep 12, 2012 · 8 comments

Comments

@fr-freelance
Copy link

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.

@fr-freelance
Copy link
Author

Actually I removed ENT_HTML5 on the diff patch because this fails on PHP < 5.4, so here is the static method :

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

@erfanatp
Copy link

See this https://github.com/xrstf/PHP-FineDiff
I used it for Farsi/Persian language and it works perfectly.

@FractalizeR
Copy link

Was this merged into the core?

@gorhill gorhill mentioned this issue Jul 8, 2016
@baceto90
Copy link

baceto90 commented Jul 8, 2016

@fr-freelance can you upload patch again?

@gorhill
Copy link
Owner

gorhill commented Jul 8, 2016

There is a PR here, you could try to patch it manually. I just don't maintain this project anymore, and the purpose was to have efficient diff for ASCII-based text using PHP -- so that PR would defeat the primary purpose of the project, hence I never merged it.

@erfanatp
Copy link

erfanatp commented Jul 8, 2016

Here is the download link.
@FractalizeR
@baceto90

@baceto90
Copy link

baceto90 commented Jul 8, 2016

The example on that page: http://www.raymondhill.net/finediff/viewdiff-ex.php work perfect for me with Latin and Cyrillic symbols. I follow the instructions for usage, but only work with Latin symbols. When i try to diff strings with Cyrillic, here is the result:
default
I wonder why the code does not work for me...

@dimaninc
Copy link

dimaninc commented Dec 6, 2018

@baceto90 it works this way ok for cyrillic

$origEnc = 'UTF-8';
$enc = 'HTML-ENTITIES';
$oldValue = mb_convert_encoding($oldValue, $enc, $origEnc);
$newValue = mb_convert_encoding($newValue, $enc, $origEnc);
$diff = new FineDiff($oldValue, $newValue, FineDiff::$paragraphGranularity);
echo html_entity_decode(mb_convert_encoding($diff->renderDiffToHTML(), $origEnc, $enc));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants