PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Helpers / global / utf8.php

utf8.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.1.0, at back/Helpers/global/utf8.php

63 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || die('Restricted Access');
3
4 // utf8_encode is deprecated in PHP 8.2
5 function acym_utf8Encode(string $string): string
6 {
7 if (function_exists('mb_convert_encoding')) {
8 return mb_convert_encoding($string, 'UTF-8', 'ISO-8859-1');
9 } else {
10 $string .= $string;
11 $len = strlen($string);
12
13 for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
14 if ($string[$i] < "\x80") {
15 $string[$j] = $string[$i];
16 } elseif ($string[$i] < "\xC0") {
17 $string[$j] = "\xC2";
18 $string[++$j] = $string[$i];
19 } else {
20 $string[$j] = "\xC3";
21 $string[++$j] = chr(ord($string[$i]) - 64);
22 }
23 }
24
25 return substr($string, 0, $j);
26 }
27 }
28
29 // utf8_decode is deprecated in PHP 8.2
30 function acym_utf8Decode(string $string): string
31 {
32 if (function_exists('mb_convert_encoding')) {
33 return mb_convert_encoding($string, 'ISO-8859-1', 'UTF-8');
34 } else {
35 $newString = (string)$string;
36 $len = strlen($newString);
37
38 for ($i = 0, $j = 0; $i < $len; ++$i, ++$j) {
39 switch ($newString[$i] & "\xF0") {
40 case "\xC0":
41 case "\xD0":
42 $c = (ord($newString[$i] & "\x1F") << 6) | ord($newString[++$i] & "\x3F");
43 $newString[$j] = $c < 256 ? chr($c) : '?';
44 break;
45
46 case "\xF0":
47 ++$i;
48 // no break
49
50 case "\xE0":
51 $newString[$j] = '?';
52 $i += 2;
53 break;
54
55 default:
56 $newString[$j] = $newString[$i];
57 }
58 }
59
60 return substr($newString, 0, $j);
61 }
62 }
63