PHP-FineDiff icon indicating copy to clipboard operation
PHP-FineDiff copied to clipboard

UTF-8 diff patch

Open fr-freelance opened this issue 12 years ago • 8 comments

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 avatar Sep 12 '12 16:09 fr-freelance

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'); }

fr-freelance avatar Sep 12 '12 16:09 fr-freelance

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

erfanatp avatar Aug 17 '15 19:08 erfanatp

Was this merged into the core?

FractalizeR avatar Oct 05 '15 09:10 FractalizeR

@fr-freelance can you upload patch again?

baceto90 avatar Jul 08 '16 16:07 baceto90

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.

gorhill avatar Jul 08 '16 16:07 gorhill

Here is the download link. @FractalizeR @baceto90

erfanatp avatar Jul 08 '16 16:07 erfanatp

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...

baceto90 avatar Jul 08 '16 17:07 baceto90

@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));

dimaninc avatar Dec 06 '18 20:12 dimaninc