| @@ -1,3 +1,17 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | - | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * convert Unicode entities | |
| 5 | + * */ | |
| 6 | +function deepl_unicode_decode( $string ) { | |
| 7 | + $string = preg_replace_callback( '#\\\\u([0-9a-fA-F]{4})#', function ( $match ) { | |
| 8 | + return mb_convert_encoding( pack( 'H*', $match[1] ), 'UTF-8', 'UCS-2BE' ); | |
| 9 | + }, $string ); | |
| 10 | + $string = str_replace( '\u0002', ' ', $string ); | |
| 11 | + $string = preg_replace_callback('/&#x([0-9a-fA-F]{3,4});/', function ($match) { | |
| 12 | + return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE'); | |
| 13 | + }, $string); | |
| 14 | + //$string = preg_replace_callback('/&#([0-9a-fA-F]{3,4});/', function ($match) { return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE'); }, $string); | |
| 15 | + return $string; | |
| 16 | +} | |
| 17 | + | |